@@ -277,10 +277,13 @@ def apply(
277277 if id_list not given, all items in the database that
278278 match the filter are returned as a list of handles
279279 """
280- start_time = time .time ()
280+ t0 = time .perf_counter ()
281281 for rule in self .flist :
282282 rule .requestprepare (db , user )
283- LOG .debug ("Prepare time: %s seconds" , time .time () - start_time )
283+ t1 = time .perf_counter ()
284+ LOG .debug ("Prepare time: %s seconds" , t1 - t0 )
285+ if user :
286+ user .notify ("Prepare time: %.3fs" % (t1 - t0 ))
284287
285288 if self .logical_op == "and" :
286289 apply_logical_op = self .and_test
@@ -291,8 +294,6 @@ def apply(
291294 else :
292295 raise Exception ("invalid operator: %r" % self .logical_op )
293296
294- start_time = time .time ()
295-
296297 # build the starting set of possible_handles to be filtered
297298 possible_handles : Set [PrimaryObjectHandle ]
298299 if id_list is not None :
@@ -312,20 +313,22 @@ def apply(
312313 else :
313314 possible_handles = set (self .get_all_handles (db ))
314315
316+ t2 = time .perf_counter ()
315317 res = self .apply_logical_op_to_all (db , possible_handles , apply_logical_op , user )
318+ t3 = time .perf_counter ()
319+ LOG .debug ("Apply time: %s seconds" , t3 - t2 )
320+ if user :
321+ user .notify ("Apply time: %.3fs" % (t3 - t2 ))
316322
317323 # convert the filtered set of handles to the correct result type
318324 if id_list is not None and tupleind is not None :
319- # convert the final_list of handles back to the corresponding final_list of tuples
320- res = sorted (
321- [handle_tuple [handle ] for handle in res ],
322- key = lambda x : id_list .index (x ),
323- )
325+ # filter id_list to only matched handles, preserving original order
326+ res_set = set (res )
327+ res = [item for item in id_list if item [tupleind ] in res_set ]
324328 elif tree :
325329 # sort final_list into the same order as traversed by get_tree_cursor
326- res = sorted (res , key = lambda x : tree_handles .index (x ))
327-
328- LOG .debug ("Apply time: %s seconds" , time .time () - start_time )
330+ tree_pos = {h : i for i , h in enumerate (tree_handles )}
331+ res = sorted (res , key = lambda x : tree_pos [x ])
329332
330333 for rule in self .flist :
331334 rule .requestreset ()
0 commit comments