mirror of
https://github.com/ansible/awx.git
synced 2026-02-23 22:16:00 -03:30
Manually run subquery for parent event updates (#14044)
Fixes a long query when processing playbook_on_stats events
This commit is contained in:
@@ -4,6 +4,7 @@ import datetime
|
|||||||
from datetime import timezone
|
from datetime import timezone
|
||||||
import logging
|
import logging
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
import time
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import ObjectDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
@@ -383,8 +384,17 @@ class BasePlaybookEvent(CreatedModifiedModel):
|
|||||||
.distinct()
|
.distinct()
|
||||||
) # noqa
|
) # noqa
|
||||||
|
|
||||||
job.get_event_queryset().filter(uuid__in=changed).update(changed=True)
|
# NOTE: we take a set of changed and failed parent uuids because the subquery
|
||||||
job.get_event_queryset().filter(uuid__in=failed).update(failed=True)
|
# complicates the plan with large event tables causing very long query execution time
|
||||||
|
changed_start = time.time()
|
||||||
|
changed_res = job.get_event_queryset().filter(uuid__in=set(changed)).update(changed=True)
|
||||||
|
failed_start = time.time()
|
||||||
|
failed_res = job.get_event_queryset().filter(uuid__in=set(failed)).update(failed=True)
|
||||||
|
logger.debug(
|
||||||
|
f'Event propagation for job {job.id}: '
|
||||||
|
f'marked {changed_res} as changed in {failed_start - changed_start:.4f}s, '
|
||||||
|
f'{failed_res} as failed in {time.time() - failed_start:.4f}s'
|
||||||
|
)
|
||||||
|
|
||||||
for field in ('playbook', 'play', 'task', 'role'):
|
for field in ('playbook', 'play', 'task', 'role'):
|
||||||
value = force_str(event_data.get(field, '')).strip()
|
value = force_str(event_data.get(field, '')).strip()
|
||||||
|
|||||||
Reference in New Issue
Block a user