Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,33 @@ def update_job_metadata_and_tags(db_cursor, job_id, table_prefix, tag_ids, archi


def update_archive_metadata(db_cursor, table_prefix, archive_stats):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be clearer for future devs if we implement it as follows:

  • Create default_creation_stats with the default values
  • Validate the default keys don't exist
  • Iterate over stats_to_update and add each kv-pair to default_creation_stats
  • The rest of the logic, except in the query, use default_creation_stats

Obviously, the names wouldn't make sense anymore, so how about renaming:

  • default_creation_stats -> stats_to_update
  • stats_to_update -> required_stat_names

archive_stats_defaults = {
"begin_timestamp": 0,
"end_timestamp": 0,
"creator_id": "",
stats_to_update = {
# Use defaults for values clp-s doesn't output
"creation_ix": 0,
"creator_id": "",
}
for k, v in archive_stats_defaults.items():
archive_stats.setdefault(k, v)
keys = ", ".join(archive_stats.keys())
value_placeholders = ", ".join(["%s"] * len(archive_stats))

# Validate clp-s doesn't output the set kv-pairs
for key in stats_to_update:
if key in archive_stats:
raise ValueError(f"Unexpected key '{key}' in archive stats")

required_stat_names = [
"begin_timestamp",
"end_timestamp",
"id",
"size",
"uncompressed_size",
]
for stat_name in required_stat_names:
stats_to_update[stat_name] = archive_stats[stat_name]

keys = ", ".join(stats_to_update.keys())
value_placeholders = ", ".join(["%s"] * len(stats_to_update))
query = (
f"INSERT INTO {table_prefix}{ARCHIVES_TABLE_SUFFIX} ({keys}) VALUES ({value_placeholders})"
)
db_cursor.execute(query, list(archive_stats.values()))
db_cursor.execute(query, list(stats_to_update.values()))


def _generate_fs_logs_list(
Expand Down