Skip to content

Commit 2a51cbf

Browse files
committed
Merge branch 'next' of https://github.com/Geode-solutions/OpenGeodeWeb-Back into fix/database
2 parents eedd720 + 58397b9 commit 2a51cbf

File tree

2 files changed

+45
-33
lines changed

2 files changed

+45
-33
lines changed

requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# pip-compile --output-file=./requirements.txt --pre ./requirements.in
66
#
7-
asgiref==3.*,>=3.9.2
7+
asgiref~=3.0
88
# via flask
99
blinker==1.*,>=1.9.0
1010
# via flask
@@ -30,6 +30,7 @@ jinja2==3.*,>=3.1.6
3030
markupsafe==3.*,>=3.0.3
3131
# via
3232
# jinja2
33+
# opengeodeweb-microservice
3334
# werkzeug
3435
opengeode-core==15.27.4
3536
# via
@@ -59,3 +60,4 @@ werkzeug==3.0.3
5960
# -r requirements.in
6061
# flask
6162
# flask-cors
63+
# opengeodeweb-microservice

src/opengeodeweb_back/utils_functions.py

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import zipfile
66
from collections.abc import Callable
77
from typing import Any
8+
from concurrent.futures import ThreadPoolExecutor
89

910
# Third party imports
1011
import flask
@@ -174,38 +175,47 @@ def save_all_viewables_and_return_info(
174175
additional_files=additional_files,
175176
)
176177
data_path = create_data_folder_from_id(data_entry.id)
177-
saved_native_file_path = geode_functions.save(
178-
geode_object,
179-
data,
180-
data_path,
181-
"native." + data.native_extension(),
182-
)
183-
saved_viewable_file_path = geode_functions.save_viewable(
184-
geode_object, data, data_path, "viewable"
185-
)
186-
saved_light_viewable_file_path = geode_functions.save_light_viewable(
187-
geode_object, data, data_path, "light_viewable"
188-
)
189-
with open(saved_light_viewable_file_path, "rb") as f:
190-
binary_light_viewable = f.read()
191-
data_entry.native_file_name = os.path.basename(saved_native_file_path[0])
192-
data_entry.viewable_file_name = os.path.basename(saved_viewable_file_path)
193-
data_entry.light_viewable = os.path.basename(saved_light_viewable_file_path)
194-
195-
session = get_session()
196-
if session:
197-
session.commit()
198-
199-
return {
200-
"native_file_name": data_entry.native_file_name,
201-
"viewable_file_name": data_entry.viewable_file_name,
202-
"id": data_entry.id,
203-
"object_type": geode_functions.get_object_type(geode_object),
204-
"binary_light_viewable": binary_light_viewable.decode("utf-8"),
205-
"geode_object": data_entry.geode_object,
206-
"input_files": data_entry.input_file,
207-
"additional_files": data_entry.additional_files,
208-
}
178+
with ThreadPoolExecutor() as executor:
179+
native_future = executor.submit(
180+
geode_functions.save,
181+
geode_object,
182+
data,
183+
data_path,
184+
"native." + data.native_extension(),
185+
)
186+
viewable_future = executor.submit(
187+
geode_functions.save_viewable, geode_object, data, data_path, "viewable"
188+
)
189+
light_viewable_future = executor.submit(
190+
geode_functions.save_light_viewable,
191+
geode_object,
192+
data,
193+
data_path,
194+
"light_viewable",
195+
)
196+
saved_light_viewable_file_path = light_viewable_future.result()
197+
with open(saved_light_viewable_file_path, "rb") as f:
198+
binary_light_viewable = f.read()
199+
saved_native_file_path = native_future.result()
200+
saved_viewable_file_path = viewable_future.result()
201+
data_entry.native_file_name = os.path.basename(saved_native_file_path[0])
202+
data_entry.viewable_file_name = os.path.basename(saved_viewable_file_path)
203+
data_entry.light_viewable = os.path.basename(saved_light_viewable_file_path)
204+
205+
session = get_session()
206+
if session:
207+
session.commit()
208+
209+
return {
210+
"native_file_name": data_entry.native_file_name,
211+
"viewable_file_name": data_entry.viewable_file_name,
212+
"id": data_entry.id,
213+
"object_type": geode_functions.get_object_type(geode_object),
214+
"binary_light_viewable": binary_light_viewable.decode("utf-8"),
215+
"geode_object": data_entry.geode_object,
216+
"input_files": data_entry.input_file,
217+
"additional_files": data_entry.additional_files,
218+
}
209219

210220

211221
def generate_native_viewable_and_light_viewable_from_object(

0 commit comments

Comments
 (0)