| 
5 | 5 | import zipfile  | 
6 | 6 | from collections.abc import Callable  | 
7 | 7 | from typing import Any  | 
 | 8 | +from concurrent.futures import ThreadPoolExecutor  | 
8 | 9 | 
 
  | 
9 | 10 | # Third party imports  | 
10 | 11 | import flask  | 
@@ -174,38 +175,47 @@ def save_all_viewables_and_return_info(  | 
174 | 175 |         additional_files=additional_files,  | 
175 | 176 |     )  | 
176 | 177 |     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 | +        }  | 
209 | 219 | 
 
  | 
210 | 220 | 
 
  | 
211 | 221 | def generate_native_viewable_and_light_viewable_from_object(  | 
 | 
0 commit comments