Skip to content

Commit

Permalink
reduce memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ElJocho committed Oct 10, 2023
1 parent e6eb49b commit 460d7e3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 2 additions & 3 deletions sketch_map_tool/database/client_flask.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 5 additions & 2 deletions sketch_map_tool/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 460d7e3

Please sign in to comment.