Skip to content

Commit 71e5f14

Browse files
committed
Fix all scoreboard section
1 parent 239b6ee commit 71e5f14

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

db/scores.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package db
33
import (
44
"encoding/json"
55
"fmt"
6+
"math"
7+
"time"
8+
69
"github.com/Quaver/api2/enums"
710
"github.com/redis/go-redis/v9"
811
"gorm.io/gorm"
9-
"math"
10-
"time"
1112
)
1213

1314
type Score struct {
@@ -400,12 +401,15 @@ func GetAllScoresForMap(md5 string) ([]*Score, error) {
400401
var scores = make([]*Score, 0)
401402

402403
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
409413
)
410414
%v`, getSelectUserScoreboardQuery(100)), md5).
411415
Scan(&scores)

0 commit comments

Comments
 (0)