Skip to content

Commit 43752bc

Browse files
camdCameron Dawson
andauthored
fix: Use original group_results api with optimized indexes (#8953)
Co-authored-by: Cameron Dawson <[email protected]>
1 parent 8b60d79 commit 43752bc

File tree

2 files changed

+2
-89
lines changed

2 files changed

+2
-89
lines changed

treeherder/log_parser/failureline.py

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,7 @@ def replace_astral(log_list):
193193
yield item
194194

195195

196-
def get_group_results_legacy(repository, push):
197-
"""
198-
Legacy implementation - preserved for testing and comparison.
199-
Performance: ~3.3 seconds average.
200-
"""
196+
def get_group_results(repository, push):
201197
groups = Group.objects.filter(
202198
job_logs__job__push__revision=push.revision,
203199
job_logs__job__push__repository=repository,
@@ -215,63 +211,3 @@ def get_group_results_legacy(repository, push):
215211
)
216212

217213
return by_task_id
218-
219-
220-
def get_group_results(repository, push):
221-
"""
222-
OPTIMIZED IMPLEMENTATION - Best performing non-cached query.
223-
224-
Performance: ~0.129s (27% faster than legacy 0.176s)
225-
226-
This implementation uses an optimized SQL query starting from the job table
227-
for the best join performance with the new database indexes.
228-
229-
RECOMMENDED DATABASE INDEXES (already applied):
230-
231-
-- Composite indexes for optimal query performance
232-
CREATE INDEX CONCURRENTLY idx_group_status_composite
233-
ON group_status(status, job_log_id, group_id);
234-
235-
CREATE INDEX CONCURRENTLY idx_job_push_id
236-
ON job(push_id);
237-
238-
CREATE INDEX CONCURRENTLY idx_job_log_job_id
239-
ON job_log(job_id);
240-
241-
CREATE INDEX CONCURRENTLY idx_taskcluster_metadata_job_id
242-
ON taskcluster_metadata(job_id);
243-
244-
CREATE INDEX CONCURRENTLY idx_push_revision_repo
245-
ON push(revision, repository_id);
246-
"""
247-
from django.db import connection
248-
249-
ok_status = GroupStatus.OK
250-
251-
query = """
252-
SELECT
253-
tcm.task_id,
254-
g.name,
255-
gs.status
256-
FROM job j
257-
INNER JOIN taskcluster_metadata tcm ON j.id = tcm.job_id
258-
INNER JOIN job_log jl ON j.id = jl.job_id
259-
INNER JOIN group_status gs ON jl.id = gs.job_log_id
260-
INNER JOIN "group" g ON gs.group_id = g.id
261-
WHERE j.push_id = %s
262-
AND gs.status IN (%s, %s)
263-
ORDER BY tcm.task_id
264-
"""
265-
266-
by_task_id = {}
267-
268-
with connection.cursor() as cursor:
269-
cursor.execute(query, [push.id, GroupStatus.OK, GroupStatus.ERROR])
270-
rows = cursor.fetchall()
271-
272-
for task_id, group_name, status in rows:
273-
if task_id not in by_task_id:
274-
by_task_id[task_id] = {}
275-
by_task_id[task_id][group_name] = status == ok_status
276-
277-
return by_task_id

treeherder/webapp/api/push.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
from rest_framework.response import Response
1111
from rest_framework.status import HTTP_400_BAD_REQUEST, HTTP_404_NOT_FOUND
1212

13-
from treeherder.log_parser.failureline import (
14-
get_group_results,
15-
get_group_results_legacy,
16-
)
13+
from treeherder.log_parser.failureline import get_group_results
1714
from treeherder.model.models import Commit, Job, JobType, Push, Repository
1815
from treeherder.push_health.builds import get_build_failures
1916
from treeherder.push_health.compare import get_commit_history
@@ -493,9 +490,6 @@ def report_if_short_revision(self, param, revision):
493490
def group_results(self, request, project):
494491
"""
495492
Return the results of all the test groups for this push.
496-
497-
OPTIMIZED IMPLEMENTATION - Best performing non-cached query.
498-
Performance: ~0.129s (27% faster than legacy 0.176s)
499493
"""
500494
revision = request.query_params.get("revision")
501495

@@ -507,20 +501,3 @@ def group_results(self, request, project):
507501

508502
groups = get_group_results(repository, push)
509503
return Response(groups)
510-
511-
@action(detail=False)
512-
def group_results_legacy(self, request, project):
513-
"""
514-
LEGACY ENDPOINT - Original implementation preserved for comparison.
515-
Performance: ~0.176s (baseline for comparison)
516-
"""
517-
revision = request.query_params.get("revision")
518-
519-
try:
520-
repository = Repository.objects.get(name=project)
521-
push = Push.objects.get(revision=revision, repository=repository)
522-
except Push.DoesNotExist:
523-
return Response(f"No push with revision: {revision}", status=HTTP_404_NOT_FOUND)
524-
525-
groups = get_group_results_legacy(repository, push)
526-
return Response(groups)

0 commit comments

Comments
 (0)