-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creates and joins against a view used to get the rank of a replay. (#508
) See #507. This new function is not yet used, but I figure we can replace the existing annotate_with_rank() with it. The new approach allows for us to more easily get ranks in situations where the required data isn't returned in the query, which is nice. It's a bit slower, so we may need to convert this to a "materialized view", but I think it's still acceptable right now, especially with the new index.
- Loading branch information
Showing
5 changed files
with
263 additions
and
4 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
project/thscoreboard/replays/migrations/0040_replayrank_replay_scoring_division.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Generated by Django 4.2.4 on 2024-08-18 22:49 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("replays", "0039_replaystage_th128_frozen_area"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="ReplayRank", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
], | ||
options={ | ||
"db_table": "replays_rank", | ||
"managed": False, | ||
}, | ||
), | ||
migrations.AddIndex( | ||
model_name="replay", | ||
index=models.Index( | ||
fields=[ | ||
"replay_type", | ||
"shot_id", | ||
"difficulty", | ||
"route_id", | ||
"category", | ||
"-score", | ||
], | ||
name="scoring_division", | ||
), | ||
), | ||
] |
31 changes: 31 additions & 0 deletions
31
project/thscoreboard/replays/migrations/0041_replay_rank_view.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Generated by Django 4.2.4 on 2024-08-18 23:14 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("replays", "0040_replayrank_replay_scoring_division"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunSQL( | ||
sql=""" | ||
CREATE OR REPLACE VIEW replays_rank | ||
AS | ||
SELECT row_number() over () as id, replay, score, shot_id, difficulty, route_id, category, place | ||
FROM ( | ||
SELECT id as replay, score, shot_id, difficulty, route_id, category, rank() OVER (PARTITION BY shot_id, difficulty, route_id, category ORDER BY score DESC, created, id) as place | ||
FROM replays_replay | ||
WHERE replay_type = 1 -- FULL_GAME | ||
AND category = 1 -- STANDARD | ||
) AS ranked | ||
WHERE place <= 3 | ||
ORDER BY shot_id, difficulty, route_id, category, place desc | ||
; | ||
""", | ||
reverse_sql=""" | ||
DROP VIEW replays_rank; | ||
""", | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters