File tree Expand file tree Collapse file tree 4 files changed +48
-0
lines changed Expand file tree Collapse file tree 4 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ func init() {
54
54
RootCmd .AddCommand (commands .DeleteScoreCmd )
55
55
RootCmd .AddCommand (commands .FixStatsCmd )
56
56
RootCmd .AddCommand (commands .UpdateStripePriceId )
57
+ RootCmd .AddCommand (commands .ClanRecalculateCommand )
57
58
58
59
// Migrations
59
60
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 ClanRecalculateCommand = & cobra.Command {
10
+ Use : "clan:recalc" ,
11
+ Short : "Recalculates all clans" ,
12
+ Run : func (cmd * cobra.Command , args []string ) {
13
+ clans , err := db .GetClans ()
14
+
15
+ if err != nil {
16
+ logrus .Error (err )
17
+ return
18
+ }
19
+
20
+ for _ , clan := range clans {
21
+ if err := db .PerformFullClanRecalculation (clan ); err != nil {
22
+ logrus .Error (err )
23
+ return
24
+ }
25
+
26
+ logrus .Info ("Recalculated clan: " , clan .Id )
27
+ }
28
+ },
29
+ }
Original file line number Diff line number Diff line change @@ -99,6 +99,9 @@ func PerformFullClanRecalculation(clan *Clan) error {
99
99
return err
100
100
}
101
101
102
+ if err := UpdateClanLeaderboard (clan , mode ); err != nil {
103
+ return err
104
+ }
102
105
}
103
106
104
107
return nil
Original file line number Diff line number Diff line change @@ -81,6 +81,21 @@ func (clan *Clan) Insert() error {
81
81
return nil
82
82
}
83
83
84
+ // GetClans Retrieves all clans from the db
85
+ func GetClans () ([]* Clan , error ) {
86
+ clans := make ([]* Clan , 0 )
87
+
88
+ result := SQL .
89
+ Preload ("Stats" ).
90
+ Find (& clans )
91
+
92
+ if result .Error != nil {
93
+ return nil , result .Error
94
+ }
95
+
96
+ return clans , nil
97
+ }
98
+
84
99
// GetClanById Gets a clan from the database by its id
85
100
func GetClanById (id int ) (* Clan , error ) {
86
101
var clan * Clan
You can’t perform that action at this time.
0 commit comments