Skip to content
Snippets Groups Projects

Merge parents caches into the current task one

Merged Eva Bardou requested to merge merge-parents-cache into master
All threads resolved!
4 files
+ 288
323
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 17
16
@@ -80,7 +80,7 @@ def create_tables():
db.create_tables([CachedElement, CachedTranscription])
def merge_parents_caches(parent_ids, current_database, data_dir="/data"):
def merge_parents_cache(parent_ids, current_database, data_dir="/data"):
"""
Merge all the potential parent task's databases into the existing local one
"""
@@ -102,20 +102,21 @@ def merge_parents_caches(parent_ids, current_database, data_dir="/data"):
# Open a connection on current database
connection = sqlite3.connect(current_database)
with connection.cursor() as cursor:
for idx, path in enumerate(paths):
# Merge each table into the local database
statements = [
"PRAGMA page_size=80000;",
"PRAGMA synchronous=OFF;",
f"ATTACH DATABASE '{path}' AS source_{idx};",
f"REPLACE INTO elements SELECT * FROM source_{idx}.elements;",
f"REPLACE INTO transcriptions SELECT * FROM source_{idx}.transcriptions;",
]
for statement in statements:
cursor.execute(statement)
connection.commit()
cursor = connection.cursor()
# Merge each table into the local database
for idx, path in enumerate(paths):
logger.info(f"Merging parent db {path} into {current_database}")
statements = [
"PRAGMA page_size=80000;",
"PRAGMA synchronous=OFF;",
f"ATTACH DATABASE '{path}' AS source_{idx};",
f"REPLACE INTO elements SELECT * FROM source_{idx}.elements;",
f"REPLACE INTO transcriptions SELECT * FROM source_{idx}.transcriptions;",
]
for statement in statements:
cursor.execute(statement)
connection.commit()
# TODO: maybe reopen peewee connection ?
Loading