Skip to content

Commit

Permalink
remove duplicate constraint check for usage insert
Browse files Browse the repository at this point in the history
  • Loading branch information
dlpbc committed Oct 10, 2024
1 parent 324d128 commit 297576a
Showing 1 changed file with 1 addition and 6 deletions.
7 changes: 1 addition & 6 deletions rctab/routers/accounting/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,13 @@ async def insert_usage(all_usage: AllUsage) -> None:
all_usage: Usage data to insert.
"""
usage_query = insert(accounting_models.usage)
update_dict = {c.name: c for c in usage_query.excluded if not c.primary_key}
on_duplicate_key_stmt = usage_query.on_conflict_do_update(
index_elements=inspect(accounting_models.usage).primary_key,
set_=update_dict,
)

logger.info("Inserting usage data")
insert_start = datetime.datetime.now()

await executemany(
database,
on_duplicate_key_stmt,
usage_query,
values=[i.model_dump() for i in all_usage.usage_list],
)
logger.info("Inserting usage data took %s", datetime.datetime.now() - insert_start)
Expand Down

0 comments on commit 297576a

Please sign in to comment.