Skip to content

Commit

Permalink
optimize & make rank recalc more accurate
Browse files Browse the repository at this point in the history
  • Loading branch information
osu!Akatsuki Developer committed Nov 26, 2022
1 parent c518f77 commit b3ba750
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
28 changes: 14 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}",
Expand Down
20 changes: 20 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b3ba750

Please sign in to comment.