bump github.com/tribalwarshelp/shared

This commit is contained in:
Dawid Wysokiński 2020-06-29 15:01:16 +02:00 committed by Kichiyaki
parent a213f2cfcd
commit f659fc9bc3
6 changed files with 18 additions and 20 deletions

View File

@ -39,10 +39,10 @@ func Attach(c *cron.Cron, db *pg.DB) error {
if _, err := c.AddFunc("30 0 * * *", h.updateServersHistory); err != nil {
return err
}
if _, err := c.AddFunc("30 1 * * *", h.updateStats); err != nil {
if _, err := c.AddFunc("30 1 * * *", h.vacuumDatabase); err != nil {
return err
}
if _, err := c.AddFunc("30 2 * * *", h.vacuumDatabase); err != nil {
if _, err := c.AddFunc("30 2 * * *", h.updateStats); err != nil {
return err
}
go func() {

View File

@ -21,7 +21,7 @@ const (
$BODY$
BEGIN
IF NEW.name <> OLD.name THEN
INSERT INTO player_name_changes(lang_version_tag,player_id,old_name,new_name,changed_on)
INSERT INTO player_name_changes(lang_version_tag,player_id,old_name,new_name,change_date)
VALUES(?1,NEW.id,OLD.name,NEW.name,CURRENT_DATE)
ON CONFLICT DO NOTHING;
END IF;

View File

@ -423,7 +423,7 @@ func (h *updateServerDataHandler) calculateDailyTribeStats(tribes []*models.Trib
dailyStats := []*models.DailyTribeStats{}
for _, historyRecord := range history {
if !h.isDateTheSameAsServerHistoryUpdatedAt(historyRecord.CreatedAt) {
if !h.isDateTheSameAsServerHistoryUpdatedAt(historyRecord.CreateDate) {
continue
}
if index := searchByID(makeTribesSearchable(tribes), historyRecord.TribeID); index != 0 {
@ -436,7 +436,7 @@ func (h *updateServerDataHandler) calculateDailyTribeStats(tribes []*models.Trib
AllPoints: tribe.AllPoints - historyRecord.AllPoints,
Rank: (tribe.Rank - historyRecord.Rank) * -1,
Dominance: tribe.Dominance - historyRecord.Dominance,
CreatedAt: historyRecord.CreatedAt,
CreateDate: historyRecord.CreateDate,
OpponentsDefeated: h.calculateODDifference(tribe.OpponentsDefeated, historyRecord.OpponentsDefeated),
})
}
@ -450,7 +450,7 @@ func (h *updateServerDataHandler) calculateDailyPlayerStats(players []*models.Pl
dailyStats := []*models.DailyPlayerStats{}
for _, historyRecord := range history {
if !h.isDateTheSameAsServerHistoryUpdatedAt(historyRecord.CreatedAt) {
if !h.isDateTheSameAsServerHistoryUpdatedAt(historyRecord.CreateDate) {
continue
}
if index := searchByID(makePlayersSearchable(players), historyRecord.PlayerID); index != 0 {
@ -460,7 +460,7 @@ func (h *updateServerDataHandler) calculateDailyPlayerStats(players []*models.Pl
Villages: player.TotalVillages - historyRecord.TotalVillages,
Points: player.Points - historyRecord.Points,
Rank: (player.Rank - historyRecord.Rank) * -1,
CreatedAt: historyRecord.CreatedAt,
CreateDate: historyRecord.CreateDate,
OpponentsDefeated: h.calculateODDifference(player.OpponentsDefeated, historyRecord.OpponentsDefeated),
})
}
@ -554,7 +554,7 @@ func (h *updateServerDataHandler) update() error {
DistinctOn("tribe_id").
Column("*").
Where("tribe_id IN (?)", pg.In(ids)).
Order("tribe_id DESC", "created_at DESC").
Order("tribe_id DESC", "create_date DESC").
Select(); err != nil && err != pg.ErrNoRows {
return errors.Wrap(err, "cannot select tribes history")
}
@ -563,7 +563,7 @@ func (h *updateServerDataHandler) update() error {
if len(todaysTribesStats) > 0 {
if _, err := tx.
Model(&todaysTribesStats).
OnConflict("ON CONSTRAINT daily_tribe_stats_tribe_id_created_at_key DO UPDATE").
OnConflict("ON CONSTRAINT daily_tribe_stats_tribe_id_create_date_key DO UPDATE").
Set("members = EXCLUDED.members").
Set("villages = EXCLUDED.villages").
Set("points = EXCLUDED.points").
@ -607,7 +607,7 @@ func (h *updateServerDataHandler) update() error {
DistinctOn("player_id").
Column("*").
Where("player_id IN (?)", pg.In(ids)).
Order("player_id DESC", "created_at DESC").Select(); err != nil && err != pg.ErrNoRows {
Order("player_id DESC", "create_date DESC").Select(); err != nil && err != pg.ErrNoRows {
return errors.Wrap(err, "cannot select players history")
}
@ -615,7 +615,7 @@ func (h *updateServerDataHandler) update() error {
if len(todaysPlayersStats) > 0 {
if _, err := tx.
Model(&todaysPlayersStats).
OnConflict("ON CONSTRAINT daily_player_stats_player_id_created_at_key DO UPDATE").
OnConflict("ON CONSTRAINT daily_player_stats_player_id_create_date_key DO UPDATE").
Set("villages = EXCLUDED.villages").
Set("points = EXCLUDED.points").
Set("rank = EXCLUDED.rank").

View File

@ -24,7 +24,7 @@ func (h *vacuumServerDBHandler) vacuum() error {
_, err = tx.Model(&models.PlayerHistory{}).
With("players", withNotExitedPlayers).
Where("player_id IN (Select id FROM players) OR player_history.created_at < ?", time.Now().Add(-1*24*time.Hour*90)).
Where("player_id IN (Select id FROM players) OR player_history.create_date < ?", time.Now().Add(-1*24*time.Hour*90)).
Delete()
if err != nil {
return errors.Wrap(err, "cannot delete old player history")
@ -32,7 +32,7 @@ func (h *vacuumServerDBHandler) vacuum() error {
_, err = tx.Model(&models.TribeHistory{}).
With("tribes", withNotExitedTribes).
Where("tribe_id IN (Select id FROM tribes) OR tribe_history.created_at < ?", time.Now().Add(-1*24*time.Hour*90)).
Where("tribe_id IN (Select id FROM tribes) OR tribe_history.create_date < ?", time.Now().Add(-1*24*time.Hour*90)).
Delete()
if err != nil {
return errors.Wrap(err, "cannot delete old tribe history")
@ -40,7 +40,7 @@ func (h *vacuumServerDBHandler) vacuum() error {
_, err = tx.Model(&models.DailyPlayerStats{}).
With("players", withNotExitedPlayers).
Where("player_id IN (Select id FROM players) OR daily_player_stats.created_at < ?", time.Now().Add(-1*24*time.Hour*90)).
Where("player_id IN (Select id FROM players) OR daily_player_stats.create_date < ?", time.Now().Add(-1*24*time.Hour*90)).
Delete()
if err != nil {
return errors.Wrap(err, "cannot delete old player stats")
@ -48,7 +48,7 @@ func (h *vacuumServerDBHandler) vacuum() error {
_, err = tx.Model(&models.DailyTribeStats{}).
With("tribes", withNotExitedTribes).
Where("tribe_id IN (Select id FROM tribes) OR daily_tribe_stats.created_at < ?", time.Now().Add(-1*24*time.Hour*90)).
Where("tribe_id IN (Select id FROM tribes) OR daily_tribe_stats.create_date < ?", time.Now().Add(-1*24*time.Hour*90)).
Delete()
if err != nil {
return errors.Wrap(err, "cannot delete old tribe stats")

2
go.mod
View File

@ -9,7 +9,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/robfig/cron/v3 v3.0.1
github.com/segmentio/encoding v0.1.14 // indirect
github.com/tribalwarshelp/shared v0.0.0-20200625131045-74c5a9b3b4f0
github.com/tribalwarshelp/shared v0.0.0-20200629123803-0cd6cb6f1e87
golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect
golang.org/x/sys v0.0.0-20200622214017-ed371f2e16b4 // indirect
google.golang.org/grpc v1.30.0 // indirect

6
go.sum
View File

@ -92,10 +92,8 @@ github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYmW5DyG0UqvY96Bu5QYsTLvCHdrgo=
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc/go.mod h1:bciPuU6GHm1iF1pBvUfxfsH0Wmnc2VbpgvbI9ZWuIRs=
github.com/tribalwarshelp/shared v0.0.0-20200625120510-6d18ee334662 h1:GBCpdHQsOrbz7xz+bTsZlFQJzKi1wsxgAeVFsNIZiH4=
github.com/tribalwarshelp/shared v0.0.0-20200625120510-6d18ee334662/go.mod h1:tf+2yTHasV6jAF3V2deZ9slNoCyBzC0fMdTjI7clf6Y=
github.com/tribalwarshelp/shared v0.0.0-20200625131045-74c5a9b3b4f0 h1:k1j0Nh2OIr1fTrCrbznjPAH+eRVpB3HYXM1sHErrayg=
github.com/tribalwarshelp/shared v0.0.0-20200625131045-74c5a9b3b4f0/go.mod h1:tf+2yTHasV6jAF3V2deZ9slNoCyBzC0fMdTjI7clf6Y=
github.com/tribalwarshelp/shared v0.0.0-20200629123803-0cd6cb6f1e87 h1:TMuZUk0wW+8dXSGVJVLRFFhLONKKYJRnLBFvbb9XTrE=
github.com/tribalwarshelp/shared v0.0.0-20200629123803-0cd6cb6f1e87/go.mod h1:tf+2yTHasV6jAF3V2deZ9slNoCyBzC0fMdTjI7clf6Y=
github.com/vmihailenco/bufpool v0.1.5/go.mod h1:fL9i/PRTuS7AELqAHwSU1Zf1c70xhkhGe/cD5ud9pJk=
github.com/vmihailenco/bufpool v0.1.11 h1:gOq2WmBrq0i2yW5QJ16ykccQ4wH9UyEsgLm6czKAd94=
github.com/vmihailenco/bufpool v0.1.11/go.mod h1:AFf/MOy3l2CFTKbxwt0mp2MwnqjNEs5H/UxrkA5jxTQ=