@@ -40,36 +40,19 @@ class ReadableFile:
4040 contents : bytes
4141
4242
43- def get_existing_flag_bridges (
44- db_session : Session , flag_ids : list [int ]
45- ) -> dict [str , TestFlagBridge ]:
46- existing_flag_bridges = (
47- db_session .query (TestFlagBridge )
48- .filter (TestFlagBridge .flag_id .in_ (flag_ids ))
49- .all ()
50- )
51- return {flag_bridge .test_id : flag_bridge for flag_bridge in existing_flag_bridges }
52-
43+ def get_repo_flag_ids (db_session : Session , repoid : int , flags : list [str ]) -> set [int ]:
44+ if not flags :
45+ return set ()
5346
54- def get_repo_flags (
55- db_session : Session , repoid : int , flags : list [str ]
56- ) -> dict [str , int ]:
57- repo_flags : list [RepositoryFlag ] = (
58- db_session .query (RepositoryFlag )
47+ return set (
48+ db_session .query (RepositoryFlag .id_ )
5949 .filter (
6050 RepositoryFlag .repository_id == repoid ,
6151 RepositoryFlag .flag_name .in_ (flags ),
6252 )
6353 .all ()
6454 )
6555
66- # flag name => flag id
67- repo_flag_mapping : dict [str , int ] = {
68- repo_flag .flag_name : repo_flag .id_ for repo_flag in repo_flags
69- }
70-
71- return repo_flag_mapping
72-
7356
7457@dataclass
7558class PytestName :
@@ -148,10 +131,7 @@ def _bulk_write_tests_to_db(
148131 daily_totals : dict [str , dict [str , str | int | list [str ]]] = dict ()
149132
150133 flags_hash = generate_flags_hash (flags )
151- repo_flags = get_repo_flags (db_session , repoid , flags )
152- existing_flag_bridges = get_existing_flag_bridges (
153- db_session , list (repo_flags .values ())
154- )
134+ repo_flag_ids = get_repo_flag_ids (db_session , repoid , flags )
155135
156136 for p in parsing_results :
157137 framework = str (p .framework ) if p .framework else None
@@ -178,10 +158,10 @@ def _bulk_write_tests_to_db(
178158 computed_name = testrun .computed_name ,
179159 )
180160
181- if test_id not in existing_flag_bridges and flags :
161+ if repo_flag_ids :
182162 test_flag_bridge_data .extend (
183- {"test_id" : test_id , "flag_id" : repo_flags [ flag ] }
184- for flag in flags
163+ {"test_id" : test_id , "flag_id" : flag_id }
164+ for flag_id in repo_flag_ids
185165 )
186166
187167 test_instance_data .append (
0 commit comments