From 460d7e30b50ae5b88d32e345f2add17238e14408 Mon Sep 17 00:00:00 2001 From: jstier Date: Tue, 10 Oct 2023 15:59:33 +0200 Subject: [PATCH] reduce memory usage --- sketch_map_tool/database/client_flask.py | 5 ++--- sketch_map_tool/routes.py | 7 +++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/sketch_map_tool/database/client_flask.py b/sketch_map_tool/database/client_flask.py index 04fb3390..a066cc28 100644 --- a/sketch_map_tool/database/client_flask.py +++ b/sketch_map_tool/database/client_flask.py @@ -87,14 +87,13 @@ def insert_files(files) -> list[int]: ) """ insert_query = "INSERT INTO blob(file_name, file) VALUES (%s, %s) RETURNING id" - data = [(secure_filename(file.filename), file.read()) for file in files] db_conn = open_connection() with db_conn.cursor() as curs: # executemany and fetchall does not work together curs.execute(create_query) ids = [] - for d in data: - curs.execute(insert_query, d) + for file in files: + curs.execute(insert_query, (secure_filename(file.filename), file.read())) ids.append(curs.fetchone()[0]) return ids diff --git a/sketch_map_tool/routes.py b/sketch_map_tool/routes.py index 6814fbe5..feba838a 100644 --- a/sketch_map_tool/routes.py +++ b/sketch_map_tool/routes.py @@ -112,9 +112,12 @@ def digitize_results_post() -> Response: f"You can only upload up to {max_nr_simultaneous_uploads} files at once." ) ids = db_client_flask.insert_files(files) - files_from_db = [db_client_flask.select_file(i) for i in ids] + file_names = [db_client_flask.select_file_name(i) for i in ids] - args = [upload_processing.read_qr_code(to_array(file)) for file in files_from_db] + args = [ + upload_processing.read_qr_code(to_array(db_client_flask.select_file(_id))) + for _id in ids + ] uuids = [args_["uuid"] for args_ in args] bboxes = [args_["bbox"] for args_ in args] map_frames = dict()