@@ -157,16 +157,32 @@ def load_user_file(file_id: int, db_session: Session) -> InMemoryChatFile:
157
157
)
158
158
159
159
160
- def load_all_user_files (
160
+ def load_in_memory_chat_files (
161
161
user_file_ids : list [int ],
162
162
user_folder_ids : list [int ],
163
163
db_session : Session ,
164
164
) -> list [InMemoryChatFile ]:
165
+ """
166
+ Loads the actual content of user files specified by individual IDs and those
167
+ within specified folder IDs into memory.
168
+
169
+ Args:
170
+ user_file_ids: A list of specific UserFile IDs to load.
171
+ user_folder_ids: A list of UserFolder IDs. All UserFiles within these folders will be loaded.
172
+ db_session: The SQLAlchemy database session.
173
+
174
+ Returns:
175
+ A list of InMemoryChatFile objects, each containing the file content (as bytes),
176
+ file ID, file type, and filename. Prioritizes loading plaintext versions if available.
177
+ """
178
+ # Use parallel execution to load files concurrently
165
179
return cast (
166
180
list [InMemoryChatFile ],
167
181
run_functions_tuples_in_parallel (
182
+ # 1. Load files specified by individual IDs
168
183
[(load_user_file , (file_id , db_session )) for file_id in user_file_ids ]
169
184
)
185
+ # 2. Load all files within specified folders
170
186
+ [
171
187
file
172
188
for folder_id in user_folder_ids
@@ -175,24 +191,47 @@ def load_all_user_files(
175
191
)
176
192
177
193
178
- def load_all_user_file_files (
194
+ def get_user_files (
179
195
user_file_ids : list [int ],
180
196
user_folder_ids : list [int ],
181
197
db_session : Session ,
182
198
) -> list [UserFile ]:
199
+ """
200
+ Fetches UserFile database records based on provided file and folder IDs.
201
+
202
+ Args:
203
+ user_file_ids: A list of specific UserFile IDs to fetch.
204
+ user_folder_ids: A list of UserFolder IDs. All UserFiles within these folders will be fetched.
205
+ db_session: The SQLAlchemy database session.
206
+
207
+ Returns:
208
+ A list containing UserFile SQLAlchemy model objects corresponding to the
209
+ specified file IDs and all files within the specified folder IDs.
210
+ It does NOT return the actual file content.
211
+ """
183
212
user_files : list [UserFile ] = []
213
+
214
+ # 1. Fetch UserFile records for specific file IDs
184
215
for user_file_id in user_file_ids :
216
+ # Query the database for a UserFile with the matching ID
185
217
user_file = (
186
218
db_session .query (UserFile ).filter (UserFile .id == user_file_id ).first ()
187
219
)
220
+ # If found, add it to the list
188
221
if user_file is not None :
189
222
user_files .append (user_file )
223
+
224
+ # 2. Fetch UserFile records for all files within specified folder IDs
190
225
for user_folder_id in user_folder_ids :
226
+ # Query the database for all UserFiles belonging to the current folder ID
227
+ # and extend the list with the results
191
228
user_files .extend (
192
229
db_session .query (UserFile )
193
230
.filter (UserFile .folder_id == user_folder_id )
194
231
.all ()
195
232
)
233
+
234
+ # 3. Return the combined list of UserFile database objects
196
235
return user_files
197
236
198
237
0 commit comments