Skip to content

Commit cd2f7ee

Browse files
committed
Split large deletion batches into smaller chunks to avoid scaring MySQL away
1 parent b007d77 commit cd2f7ee

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/acquisition/covidcast/database.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,11 @@ def delete_batch(self, cc_deletions):
333333
if isinstance(cc_deletions, str):
334334
self._cursor.execute(load_tmp_table_infile_sql)
335335
elif isinstance(cc_deletions, list):
336-
self._cursor.executemany(load_tmp_table_insert_sql, cc_deletions)
336+
def split_list(lst, n):
337+
for i in range(0, len(lst), n):
338+
yield lst[i:(i+n)]
339+
for deletions_batch in split_list(cc_deletions, 100000):
340+
self._cursor.executemany(load_tmp_table_insert_sql, deletions_batch)
337341
else:
338342
raise Exception(f"Bad deletions argument: need a filename or a list of tuples; got a {type(cc_deletions)}")
339343
self._cursor.execute(add_id_sql)

0 commit comments

Comments
 (0)