Skip to content

Commit

Permalink
refactor bulk add records to follow ORM addall pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
btylerburton committed May 13, 2024
1 parent 77292fa commit b2a8729
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion database/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,11 @@ def add_harvest_records(self, records_data: list) -> bool:
:raises Exception: if the records_data contains records with errors
"""
try:
self.db.bulk_insert_mappings(HarvestRecord, records_data)
for i, record_data in enumerate(records_data):
new_record = HarvestRecord(**record_data)
self.db.add(new_record)
if i % 1000 == 0:
self.db.flush()
self.db.commit()
return True
except Exception as e:
Expand Down

0 comments on commit b2a8729

Please sign in to comment.