Skip to content

Commit

Permalink
Fix all scoreboard section
Browse files Browse the repository at this point in the history
  • Loading branch information
Swan committed Nov 25, 2024
1 parent 239b6ee commit 71e5f14
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions db/scores.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package db
import (
"encoding/json"
"fmt"
"math"
"time"

"github.com/Quaver/api2/enums"
"github.com/redis/go-redis/v9"
"gorm.io/gorm"
"math"
"time"
)

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

result := SQL.Raw(fmt.Sprintf(`
WITH MaxRatings AS (
SELECT user_id, MAX(performance_rating) AS max_performance_rating
FROM scores
WHERE map_md5 = ?
AND failed = 0
GROUP BY user_id
WITH RankedScores AS (
SELECT
s.user_id,
s.id AS score_id,
ROW_NUMBER() OVER (PARTITION BY s.user_id ORDER BY s.performance_rating DESC, s.timestamp DESC) AS rnk
FROM scores s
WHERE
s.map_md5 = ?
AND s.failed = 0
)
%v`, getSelectUserScoreboardQuery(100)), md5).
Scan(&scores)
Expand Down

0 comments on commit 71e5f14

Please sign in to comment.