Skip to content

Commit 049960a

Browse files
committed
move code
1 parent 9ca828a commit 049960a

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

specifyweb/specify/record_merging.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,6 @@ def record_merge_fx(model_name: str, old_model_ids: List[int], new_model_id: int
192192
except ValueError:
193193
continue
194194

195-
# Handle case of updating a large amount of record ids in a foreign table.
196-
# Example: handle case of updating a large amount of agent ids in the audit logs.
197-
# Fix by optimizing the query by consolidating it here
198-
if model_name.lower() in MERGING_OPTIMIZATION_FIELDS and \
199-
table_name.lower() in MERGING_OPTIMIZATION_FIELDS[model_name.lower()]:
200-
if field_name in MERGING_OPTIMIZATION_FIELDS[model_name.lower()][table_name.lower()]:
201-
query = Q(**{field_name: old_model_ids[0]})
202-
for old_model_id in old_model_ids[1:]:
203-
query.add(Q(**{field_name: old_model_id}), Q.OR)
204-
foreign_model.objects.filter(query).update(**{field_name: new_model_id})
205-
progress(1, 0) if progress is not None else None
206-
continue
207195

208196
apply_order = add_ordering_to_key(table_name.lower().title())
209197
# BUG: timestampmodified could be null for one record, and not the other
@@ -221,6 +209,18 @@ def record_merge_fx(model_name: str, old_model_ids: List[int], new_model_id: int
221209
field_name_id = f'{field_name}_id'
222210
if not hasattr(foreign_model, field_name_id):
223211
continue
212+
# Handle case of updating a large amount of record ids in a foreign table.
213+
# Example: handle case of updating a large amount of agent ids in the audit logs.
214+
# Fix by optimizing the query by consolidating it here
215+
if model_name.lower() in MERGING_OPTIMIZATION_FIELDS and \
216+
table_name.lower() in MERGING_OPTIMIZATION_FIELDS[model_name.lower()]:
217+
if field_name_id in MERGING_OPTIMIZATION_FIELDS[model_name.lower()][table_name.lower()]:
218+
query = Q(**{field_name_id: old_model_ids[0]})
219+
for old_model_id in old_model_ids[1:]:
220+
query.add(Q(**{field_name_id: old_model_id}), Q.OR)
221+
foreign_model.objects.filter(query).update(**{field_name_id: new_model_id})
222+
progress(1, 0) if progress is not None else None
223+
continue
224224

225225
# Filter the objects in the foreign model that references the old target model
226226
foreign_objects = filter_and_lock_target_objects(foreign_model, old_model_ids, field_name_id)

0 commit comments

Comments
 (0)