Skip to content

Commit

Permalink
commands - commit changes after every batch/file has been processed t…
Browse files Browse the repository at this point in the history
…o avoid increasingly large journaling file
  • Loading branch information
MatteoCampinoti94 committed Jan 15, 2025
1 parent 5c6f1c6 commit f5fb84c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 0 deletions.
12 changes: 12 additions & 0 deletions digiarch/commands/edit/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ def cmd_action_original_convert(
set_action(ctx, database, file, "convert", data, reason, dry_run, log_stdout)
if lock:
set_lock(ctx, database, file, reason, dry_run, log_stdout)
if not dry_run:
database.commit()

end_program(ctx, database, exception, dry_run, log_file, log_stdout)

Expand Down Expand Up @@ -271,6 +273,8 @@ def cmd_action_original_extract(
set_action(ctx, database, file, "extract", data, reason, dry_run, log_stdout)
if lock:
set_lock(ctx, database, file, reason, dry_run, log_stdout)
if not dry_run:
database.commit()

end_program(ctx, database, exception, dry_run, log_file, log_stdout)

Expand Down Expand Up @@ -327,6 +331,8 @@ def cmd_action_original_manual(
set_action(ctx, database, file, "manual", data, reason, dry_run, log_stdout)
if lock:
set_lock(ctx, database, file, reason, dry_run, log_stdout)
if not dry_run:
database.commit()

end_program(ctx, database, exception, dry_run, log_file, log_stdout)

Expand Down Expand Up @@ -392,6 +398,8 @@ def cmd_action_original_ignore(
set_action(ctx, database, file, "ignore", data, reason, dry_run, log_stdout)
if lock:
set_lock(ctx, database, file, reason, dry_run, log_stdout)
if not dry_run:
database.commit()

end_program(ctx, database, exception, dry_run, log_file, log_stdout)

Expand Down Expand Up @@ -467,6 +475,8 @@ def cmd_action_original_copy(
set_action(ctx, database, file, action, data, reason, dry_run, log_stdout)
if lock:
set_lock(ctx, database, file, reason, dry_run, log_stdout)
if not dry_run:
database.commit()

end_program(ctx, database, exception, dry_run, log_file, log_stdout)

Expand Down Expand Up @@ -520,6 +530,8 @@ def cmd_action_master_convert(
with ExceptionManager(BaseException) as exception:
for file in query_table(database.master_files, query, [("lower(relative_path)", "asc")]):
set_master_convert(ctx, database, file, data, action_type, reason, dry_run)
if not dry_run:
database.commit()

end_program(ctx, database, exception, dry_run, log_file, log_stdout)

Expand Down
2 changes: 2 additions & 0 deletions digiarch/commands/edit/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def edit_file_value(
setattr(file, "lock", True)
table.update(file)
database.log.insert(event)
database.commit()
event.log(INFO, *loggers, show_args=["uuid", "data"], path=file.relative_path)


Expand All @@ -73,5 +74,6 @@ def _handler(_ctx: Context, _avid: AVID, database: FilesDB, event: Event, file:
prev_value, next_value = event.data
setattr(file, property_name, prev_value)
table.update(file)
database.commit()

return _handler
3 changes: 3 additions & 0 deletions digiarch/commands/edit/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def remove_files(
if reset_processed:
reset_parent_processed(database, file)

database.commit()


def rollback_remove_original(_ctx: Context, avid: AVID, database: FilesDB, event: Event, file: BaseFile | None):
old_file = OriginalFile.model_validate(event.data)
Expand All @@ -153,6 +155,7 @@ def rollback_remove_original(_ctx: Context, avid: AVID, database: FilesDB, event
raise FileNotFoundError(old_file.relative_path)

database.original_files.insert(old_file)
database.commit()


@rollback("remove", rollback_remove_original)
Expand Down
1 change: 1 addition & 0 deletions digiarch/commands/edit/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,6 @@ def cmd_rename_original(

event.log(INFO, log_stdout, show_args=["uuid", "data"])
database.log.insert(event)
database.commit()

end_program(ctx, database, exception, dry_run, log_file, log_stdout)
2 changes: 2 additions & 0 deletions digiarch/commands/extract/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,5 +305,7 @@ def cmd_extract(
archive_file.action_data.ignore = IgnoreAction(template="extracted-archive")

db.original_files.update(archive_file)
if not dry_run:
db.commit()

end_program(ctx, db, exception, dry_run, log_file, log_stdout)
8 changes: 8 additions & 0 deletions digiarch/commands/identify.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ def cmd_identify_original(
None,
log_stdout,
)
if not dry_run:
db.commit()

end_program(ctx, db, exception, dry_run, log_file, log_stdout)

Expand Down Expand Up @@ -521,6 +523,8 @@ def cmd_identify_master(
while batch := list(islice(files, batch_size)):
for sf_file in siegfried.identify(*batch).files:
identify_master_file(ctx, avid, db, sf_file, custom_signatures, actions, dry_run, log_stdout)
if not dry_run:
db.commit()

end_program(ctx, db, exception, dry_run, log_file, log_stdout)

Expand Down Expand Up @@ -596,6 +600,8 @@ def cmd_identify_access(
while batch := list(islice(files, batch_size)):
for sf_file in siegfried.identify(*batch).files:
identify_converted_file(ctx, avid, db.access_files, "access", sf_file, dry_run, log_stdout)
if not dry_run:
db.commit()

end_program(ctx, db, exception, dry_run, log_file, log_stdout)

Expand Down Expand Up @@ -671,6 +677,8 @@ def cmd_identify_statutory(
while batch := list(islice(files, batch_size)):
for sf_file in siegfried.identify(*batch).files:
identify_converted_file(ctx, avid, db.statutory_files, "statutory", sf_file, dry_run, log_stdout)
if not dry_run:
db.commit()

end_program(ctx, db, exception, dry_run, log_file, log_stdout)

Expand Down

0 comments on commit f5fb84c

Please sign in to comment.