From 7c1a3d4400ebfe1431108dc31ce81044eb2e4abb Mon Sep 17 00:00:00 2001 From: JerrySentry <142266253+JerrySentry@users.noreply.github.com> Date: Wed, 1 Nov 2023 20:22:05 -0400 Subject: [PATCH] fix: speedup flag filtering in GraphQL API (#223) Speed up filtering by flags in GraphQL endpoints by rewriting the search function to be able to compute faster on average. Change it to exit each of the nested for loops quicker by not going through the entire iterator. --- services/report.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/services/report.py b/services/report.py index fe74242a5a..d691953830 100644 --- a/services/report.py +++ b/services/report.py @@ -249,14 +249,17 @@ def sessions_with_specific_flags( def files_in_sessions(commit_report: Report, session_ids: List[int]) -> List[str]: - return [ - file.name - for file in commit_report - if any( - [ - any([session.id in session_ids for session in line.sessions]) - for line in file - if line - ] - ) - ] + files, session_ids = [], set(session_ids) + for file in commit_report: + found = False + for line in file: + if line: + for session in line.sessions: + if session.id in session_ids: + found = True + break + if found: + break + if found: + files.append(file.name) + return files