File tree Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Expand file tree Collapse file tree 1 file changed +12
-8
lines changed Original file line number Diff line number Diff line change @@ -3,11 +3,12 @@ package db
3
3
import (
4
4
"encoding/json"
5
5
"fmt"
6
+ "math"
7
+ "time"
8
+
6
9
"github.com/Quaver/api2/enums"
7
10
"github.com/redis/go-redis/v9"
8
11
"gorm.io/gorm"
9
- "math"
10
- "time"
11
12
)
12
13
13
14
type Score struct {
@@ -400,12 +401,15 @@ func GetAllScoresForMap(md5 string) ([]*Score, error) {
400
401
var scores = make ([]* Score , 0 )
401
402
402
403
result := SQL .Raw (fmt .Sprintf (`
403
- WITH MaxRatings AS (
404
- SELECT user_id, MAX(performance_rating) AS max_performance_rating
405
- FROM scores
406
- WHERE map_md5 = ?
407
- AND failed = 0
408
- GROUP BY user_id
404
+ WITH RankedScores AS (
405
+ SELECT
406
+ s.user_id,
407
+ s.id AS score_id,
408
+ ROW_NUMBER() OVER (PARTITION BY s.user_id ORDER BY s.performance_rating DESC, s.timestamp DESC) AS rnk
409
+ FROM scores s
410
+ WHERE
411
+ s.map_md5 = ?
412
+ AND s.failed = 0
409
413
)
410
414
%v` , getSelectUserScoreboardQuery (100 )), md5 ).
411
415
Scan (& scores )
You can’t perform that action at this time.
0 commit comments