From b3ba75054dfe9e3b8621b8b3bed9aaa1e653bafa Mon Sep 17 00:00:00 2001 From: osu!Akatsuki Developer Date: Sat, 26 Nov 2022 22:42:29 +0000 Subject: [PATCH] optimize & make rank recalc more accurate --- main.py | 28 ++++++++++++++-------------- requirements.txt | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/main.py b/main.py index 947c798..73ef605 100755 --- a/main.py +++ b/main.py @@ -1,4 +1,11 @@ #!/usr/bin/env python3.9 +import ddtrace +ddtrace.patch_all() +from ddtrace.profiling import Profiler +Profiler().start() +from typing import Any +from typing import cast + from cmyui.mysql import AsyncSQLPool from cmyui.discord import Webhook, Embed from aiohttp import ClientSession @@ -60,24 +67,17 @@ async def recalc_ranks() -> None: for mode in modes: users = await db.fetchall( - f"select users.id, stats.pp_{mode} pp, " + f"SELECT users.id, stats.pp_{mode} pp, stats.latest_pp_awarded_{mode} AS latest_pp_awarded, " "stats.country, users.latest_activity, users.privileges " - "from users " - f"left join {stats_table} stats on stats.id = users.id " - f"where stats.pp_{mode} > 0" + "FROM users " + f"LEFT JOIN {stats_table} stats on stats.id = users.id " + f"WHERE stats.pp_{mode} > 0" ) + users = cast(list[dict[str, Any]], users) for user in users: - last_score_time = await db.fetch( - f"select max(time) as time from {scores_table} inner join beatmaps using(beatmap_md5) " - "where userid = %s and completed = 3 and ranked in (2, 3) and play_mode = %s order by pp desc limit 100", - [user["id"], STR_TO_INT_MODE[mode]] - ) - if not last_score_time or last_score_time["time"] is None: - inactive_days = 60 - else: - inactive_days = (start_time - last_score_time["time"]) / 60 / 60 / 24 - + inactive_days = (start_time - user["latest_pp_awarded"]) / 60 / 60 / 24 + if inactive_days < 60 and user["privileges"] & 1: await redis.zadd( f"ripple:{redis_board}:{mode}", diff --git a/requirements.txt b/requirements.txt index 831e4fd..e9ef5f7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,16 +4,36 @@ aioredis==1.3.1 aiosignal==1.2.0 async-timeout==4.0.2 attrs==21.4.0 +black==22.6.0 +bytecode==0.13.0 +cattrs==22.2.0 charset-normalizer==2.1.0 +click==8.1.3 cmyui==1.9.3 +ddsketch==2.0.4 +ddtrace==1.6.0 +envier==0.4.0 +exceptiongroup==1.0.1 +forbiddenfruit==0.1.4 frozenlist==1.3.0 hiredis==2.0.0 idna==3.3 +jsonschema==4.17.0 multidict==6.0.2 +mypy-extensions==0.4.3 mysql-connector-python==8.0.29 orjson==3.7.3 +packaging==21.3 +pathspec==0.9.0 +platformdirs==2.5.2 protobuf==4.21.1 PyMySQL==1.0.2 +pyparsing==3.0.9 +pyrsistent==0.19.2 +six==1.16.0 +tenacity==8.1.0 +tomli==2.0.1 typing_extensions==4.2.0 uvloop==0.16.0 +xmltodict==0.13.0 yarl==1.7.2