Skip to content

Commit

Permalink
improve /api/admin/tenants/billing
Browse files Browse the repository at this point in the history
  • Loading branch information
reiichii committed Jul 23, 2022
1 parent f5c29b8 commit 855a3be
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ docker-compose-perl.yml
docker-compose-php.yml
docker-compose-ruby.yml
docker-compose-rust.yml

docker-compose.yml
18 changes: 11 additions & 7 deletions python/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,10 @@ def billing_report_by_competition(

# memo: slow query logが多発
visit_history_summary_rows = admin_db.execute(
"SELECT player_id, MIN(created_at) AS min_created_at FROM visit_history WHERE tenant_id = %s AND competition_id = %s GROUP BY player_id",
"SELECT player_id, MIN(created_at) AS min_created_at FROM visit_history WHERE tenant_id = %s AND competition_id = %s AND created_at < %s GROUP BY player_id",
tenant_id,
competition.id,
competition.finished_at,
).fetchall()

billing_map = {}
Expand Down Expand Up @@ -466,11 +467,14 @@ def tenants_billing_handler():
# scoreが登録されていないplayerでアクセスした人 * 10
# を合計したものを
# テナントの課金とする
tenant_rows = admin_db.execute("SELECT * FROM tenant ORDER BY id DESC").fetchall()
# memo: before活かせてない
tenant_rows = admin_db.execute(
f"SELECT id, name, display_name FROM tenant ORDER BY id DESC LIMIT 10 OFFSET {before_id}",
).fetchall()
tenant_billings = []
for tenant_row in tenant_rows:
if before_id != 0 and before_id <= tenant_row.id:
continue
# if before_id != 0 and before_id <= tenant_row.id:
# continue
tenant_billing = TenantWithBilling(
id=str(tenant_row.id),
name=tenant_row.name,
Expand All @@ -479,7 +483,7 @@ def tenants_billing_handler():
)
tenant_db = connect_to_tenant_db(int(tenant_row.id))
competition_rows = tenant_db.execute(
"SELECT * FROM competition WHERE tenant_id=?", tenant_row.id
"SELECT id FROM competition WHERE tenant_id=?", tenant_row.id
).fetchall()

for competition_row in competition_rows:
Expand All @@ -489,8 +493,8 @@ def tenants_billing_handler():
tenant_billing.billing += report.billing_yen
tenant_billings.append(tenant_billing)

if len(tenant_billings) >= 10:
break
# if len(tenant_billings) >= 10:
# break

return jsonify(SuccessResult(status=True, data={"tenants": tenant_billings}))

Expand Down

0 comments on commit 855a3be

Please sign in to comment.