From 53e05797194f0397bea3b395d7ead5015d2c3472 Mon Sep 17 00:00:00 2001
From: Maximilian Moser <maximilian.moser@tuwien.ac.at>
Date: Fri, 23 Feb 2024 16:02:02 +0100
Subject: [PATCH] Utilize smarter startup logic for speeding up resultman

* utilize the new result loading functionality
* use a data structure better suited for the actual operation
---
 formatscaper/resultman.py | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/formatscaper/resultman.py b/formatscaper/resultman.py
index c816e62..01ab8a4 100755
--- a/formatscaper/resultman.py
+++ b/formatscaper/resultman.py
@@ -85,16 +85,20 @@ except Exception as e:
     print(e)
 
 try:
-    all_results = load_results(args.results) or []
-    all_results_per_record = {
-        rec: [res for res in all_results if res.record == rec]
-        for rec in {res.record for res in all_results}
+    # load the results and prepare them in the shape we need them later
+    # (Format PUID => Record => Files)
+    all_results = load_results(args.results, formats=formats) or []
+    format_record_files = {
+        format.puid: {
+            record: [result for result in format.results if result.record == record]
+            for record in {result.record for result in format.results}
+        }
+        for format in formats
     }
 except Exception as e:
-    all_results, all_results_per_record = [], {}
+    all_results, format_record_files = [], {}
     print(e)
 
-
 # color palette & settings
 palette = [
     ("border", "light gray,bold", "dark gray"),
@@ -118,10 +122,7 @@ def handle_select_format(format: Format, button: uw.Button):
     """Set up the format details side (right) based on the selected format."""
     relevant_results = {
         rec: sorted(ress, key=lambda r: r.filename)
-        for rec, ress in {
-            rec: [r for r in ress if r.format == format]
-            for rec, ress in all_results_per_record.items()
-        }.items()
+        for rec, ress in format_record_files[format.puid].items()
         if ress
     }
 
-- 
GitLab