From bbc784c720722eba9bf5bc90e30d3bd7bd283699 Mon Sep 17 00:00:00 2001 From: Ethanfel Date: Mon, 19 Jan 2026 14:17:01 +0100 Subject: [PATCH] Update engine.py --- engine.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/engine.py b/engine.py index 60e6c2e..078cf5f 100644 --- a/engine.py +++ b/engine.py @@ -63,6 +63,31 @@ class SorterEngine: cursor.execute("INSERT OR REPLACE INTO profiles VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", new_values) conn.commit() conn.close() + @staticmethod + def load_batch_parallel(image_paths, quality): + """ + Multithreaded loader: Compresses multiple images in parallel. + Returns a dictionary {path: bytes_io} + """ + import concurrent.futures + + results = {} + + # Helper function to run in thread + def process_one(path): + return path, SorterEngine.compress_for_web(path, quality) + + # Use ThreadPool to parallelize IO-bound tasks + with concurrent.futures.ThreadPoolExecutor(max_workers=8) as executor: + # Submit all tasks + future_to_path = {executor.submit(process_one, p): p for p in image_paths} + + # Gather results as they complete + for future in concurrent.futures.as_completed(future_to_path): + path, data = future.result() + results[path] = data + + return results @staticmethod def load_profiles():