File tree 2 files changed +54
-0
lines changed
2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ func init() {
48
48
RootCmd .AddCommand (commands .SupervisorActivityCmd )
49
49
RootCmd .AddCommand (commands .ClanRankMapCmd )
50
50
RootCmd .AddCommand (commands .DenyOnHoldCmd )
51
+ RootCmd .AddCommand (commands .DatabaseScoresBatchDeleteFailed )
51
52
52
53
// Migrations
53
54
RootCmd .AddCommand (migrations .MigrationPlaylistMapsetCmd )
Original file line number Diff line number Diff line change
1
+ package commands
2
+
3
+ import (
4
+ "github.com/Quaver/api2/db"
5
+ "github.com/sirupsen/logrus"
6
+ "github.com/spf13/cobra"
7
+ )
8
+
9
+ var DatabaseScoresBatchDeleteFailed = & cobra.Command {
10
+ Use : "database:scores:batch:delete" ,
11
+ Short : "Deletes every failed score" ,
12
+ Run : func (cmd * cobra.Command , args []string ) {
13
+ batchSize := 5000
14
+ offset := 0
15
+
16
+ for {
17
+ var scoreIDs []int
18
+
19
+ result := db .SQL .
20
+ Model (& db.Score {}).
21
+ Where ("failed = 1" ).
22
+ Limit (batchSize ).
23
+ Offset (offset ).
24
+ Pluck ("id" , & scoreIDs )
25
+
26
+ if result .Error != nil {
27
+ logrus .Info ("Something went wrong" )
28
+ break
29
+ }
30
+
31
+ if len (scoreIDs ) == 0 {
32
+ if offset == 0 {
33
+ logrus .Info ("No more failed scores found!" )
34
+ } else {
35
+ logrus .Info ("There are no scores left to delete!" )
36
+ }
37
+
38
+ break
39
+ }
40
+
41
+ deletedBatch := db .SQL .Where ("id IN ?" , scoreIDs ).Delete (& db.Score {})
42
+
43
+ if deletedBatch .Error != nil {
44
+ logrus .Info ("Something went wrong when deleting scores" )
45
+ break
46
+ }
47
+
48
+ logrus .Infof ("Deleted %d failed scores" , deletedBatch .RowsAffected )
49
+
50
+ offset += batchSize
51
+ }
52
+ },
53
+ }
You can’t perform that action at this time.
0 commit comments