Skip to content

Commit 2c9c7e7

Browse files
committed
Add command to recalc all clans
1 parent 2ba82e4 commit 2c9c7e7

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

cmd/console/cmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func init() {
5454
RootCmd.AddCommand(commands.DeleteScoreCmd)
5555
RootCmd.AddCommand(commands.FixStatsCmd)
5656
RootCmd.AddCommand(commands.UpdateStripePriceId)
57+
RootCmd.AddCommand(commands.ClanRecalculateCommand)
5758

5859
// Migrations
5960
RootCmd.AddCommand(migrations.MigrationPlaylistMapsetCmd)

cmd/console/commands/clan_recalc.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
}

db/clan_stats.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ func PerformFullClanRecalculation(clan *Clan) error {
9999
return err
100100
}
101101

102+
if err := UpdateClanLeaderboard(clan, mode); err != nil {
103+
return err
104+
}
102105
}
103106

104107
return nil

db/clans.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@ func (clan *Clan) Insert() error {
8181
return nil
8282
}
8383

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+
8499
// GetClanById Gets a clan from the database by its id
85100
func GetClanById(id int) (*Clan, error) {
86101
var clan *Clan

0 commit comments

Comments
 (0)