-
Notifications
You must be signed in to change notification settings - Fork 4
/
fix_multiple_completed_scores.go
52 lines (48 loc) · 1.51 KB
/
fix_multiple_completed_scores.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import "github.com/fatih/color"
func opFixMultipleCompletedScores() {
defer wg.Done()
const initQuery = "SELECT id, userid, beatmap_md5, play_mode, score FROM scores WHERE completed = 3 ORDER BY id DESC"
scores := []score{}
rows, err := db.Query(initQuery)
if err != nil {
queryError(err, initQuery)
return
}
for rows.Next() {
currentScore := score{}
rows.Scan(
¤tScore.id,
¤tScore.userid,
¤tScore.beatmapMD5,
¤tScore.score,
¤tScore.playMode,
)
scores = append(scores, currentScore)
}
verboseln("> FixMultipleCompletedScores: Fetched, now finding bugged completed scores...")
fixed := []int{}
for i := 0; i < len(scores); i++ {
if i%1000 == 0 {
verboseln("> FixMultipleCompletedScores:", i)
}
if contains(fixed, scores[i].id) {
continue
}
for j := i + 1; j < len(scores); j++ {
if contains(fixed, scores[j].id) {
continue
}
if scores[j].id != scores[i].id && scores[j].beatmapMD5 == scores[i].beatmapMD5 && scores[j].userid == scores[i].userid && scores[j].playMode == scores[i].playMode {
verbosef("> FixMultipleCompletedScores: Found duplicated completed score (%d/%d)\n", scores[i].id, scores[j].id)
if scores[j].score > scores[i].score {
op("UPDATE scores SET completed = 2 WHERE id = ?", scores[i].id)
} else {
op("UPDATE scores SET completed = 2 WHERE id = ?", scores[j].id)
}
fixed = append(fixed, scores[i].id, scores[j].id)
}
}
}
color.Green("> FixMultipleCompletedScores: done!")
}