Skip to content

Commit

Permalink
chore: optimizing query with a little trick
Browse files Browse the repository at this point in the history
  • Loading branch information
danielsoheil committed Feb 21, 2024
1 parent ee4dd9f commit 31f5fb1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cli/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ def validate_discord_webhook(value: str) -> Union[str, None]:

def calculate_admin_usage(admin_id: int) -> int:
with GetDB() as db:
return db.execute(text(f'select sum(used_traffic) / 1024 / 1024 / 1024 from (select * from node_user_usages join (select * from users where admin_id = {admin_id}) as users on users.id = node_user_usages.user_id);')).one()[0]
return db.execute(text(f'SELECT SUM(node_user_usages.used_traffic) / 1024 / 1024 / 1024 FROM node_user_usages JOIN users ON users.id = node_user_usages.user_id AND users.admin_id = {admin_id};')).one()[0]


def calculate_admin_reseted_usage(admin_id: int) -> int:
with GetDB() as db:
return db.execute(text(f'select sum(used_traffic_at_reset) / 1024 / 1024 / 1024 from (select * from user_usage_logs join (select * from users where admin_id = {admin_id}) as users on users.id = user_usage_logs.user_id);')).one()[0]
return db.execute(text(f'SELECT SUM(used_traffic_at_reset) / 1024 / 1024 / 1024 FROM user_usage_logs JOIN users ON users.id = user_usage_logs.user_id AND users.admin_id = {admin_id};')).one()[0]


@app.command(name="list")
Expand Down

0 comments on commit 31f5fb1

Please sign in to comment.