fix: insert queries in most cases should return nothing
This commit is contained in:
parent
07961fe2f3
commit
3313208707
|
@ -305,6 +305,7 @@ func (w *workerUpdateServerData) update() error {
|
|||
Set("dominance = EXCLUDED.dominance").
|
||||
Set("deleted_at = null").
|
||||
Apply(appendODSetClauses).
|
||||
Returning("NULL").
|
||||
Insert(); err != nil {
|
||||
return errors.Wrap(err, "couldn't insert tribes")
|
||||
}
|
||||
|
@ -332,6 +333,7 @@ func (w *workerUpdateServerData) update() error {
|
|||
Set("rank = EXCLUDED.rank").
|
||||
Set("dominance = EXCLUDED.dominance").
|
||||
Apply(appendODSetClauses).
|
||||
Returning("NULL").
|
||||
Insert(); err != nil {
|
||||
return errors.Wrap(err, "couldn't insert today's tribe stats")
|
||||
}
|
||||
|
@ -360,6 +362,7 @@ func (w *workerUpdateServerData) update() error {
|
|||
Set("tribe_id = EXCLUDED.tribe_id").
|
||||
Set("daily_growth = EXCLUDED.daily_growth").
|
||||
Set("deleted_at = null").
|
||||
Returning("NULL").
|
||||
Apply(appendODSetClauses).
|
||||
Insert(); err != nil {
|
||||
return errors.Wrap(err, "couldn't insert players")
|
||||
|
@ -371,7 +374,8 @@ func (w *workerUpdateServerData) update() error {
|
|||
Column("player_history.*").
|
||||
Where("player.exists = true").
|
||||
Relation("Player._").
|
||||
Order("player_id DESC", "create_date DESC").Select(); err != nil && err != pg.ErrNoRows {
|
||||
Order("player_id DESC", "create_date DESC").
|
||||
Select(); err != nil && err != pg.ErrNoRows {
|
||||
return errors.Wrap(err, "couldn't select player history records")
|
||||
}
|
||||
todaysPlayerStats := w.calculateDailyPlayerStats(playersResult.players, playerHistory)
|
||||
|
@ -383,6 +387,7 @@ func (w *workerUpdateServerData) update() error {
|
|||
Set("points = EXCLUDED.points").
|
||||
Set("rank = EXCLUDED.rank").
|
||||
Apply(appendODSetClauses).
|
||||
Returning("NULL").
|
||||
Insert(); err != nil {
|
||||
return errors.Wrap(err, "couldn't insert today's player stats")
|
||||
}
|
||||
|
@ -390,7 +395,11 @@ func (w *workerUpdateServerData) update() error {
|
|||
}
|
||||
|
||||
if len(playersResult.playersToServer) > 0 {
|
||||
if _, err := tx.Model(&playersResult.playersToServer).OnConflict("DO NOTHING").Insert(); err != nil {
|
||||
if _, err := tx.
|
||||
Model(&playersResult.playersToServer).
|
||||
OnConflict("DO NOTHING").
|
||||
Returning("NULL").
|
||||
Insert(); err != nil {
|
||||
return errors.Wrap(err, "couldn't associate players with the server")
|
||||
}
|
||||
}
|
||||
|
@ -404,6 +413,7 @@ func (w *workerUpdateServerData) update() error {
|
|||
Set("y = EXCLUDED.y").
|
||||
Set("bonus = EXCLUDED.bonus").
|
||||
Set("player_id = EXCLUDED.player_id").
|
||||
Returning("NULL").
|
||||
Insert(); err != nil {
|
||||
return errors.Wrap(err, "couldn't insert villages")
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ func (w *workerUpdateServerEnnoblements) update() error {
|
|||
}
|
||||
|
||||
if len(ennoblements) > 0 {
|
||||
if _, err := w.db.Model(&ennoblements).Insert(); err != nil {
|
||||
if _, err := w.db.Model(&ennoblements).Returning("NULL").Insert(); err != nil {
|
||||
return errors.Wrap(err, "couldn't insert ennoblements")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,13 +104,13 @@ func (w *workerUpdateServerHistory) update() error {
|
|||
}(w.server)
|
||||
|
||||
if len(ph) > 0 {
|
||||
if _, err := w.db.Model(&ph).Insert(); err != nil {
|
||||
if _, err := w.db.Model(&ph).Returning("NULL").Insert(); err != nil {
|
||||
return errors.Wrap(err, "couldn't insert players history")
|
||||
}
|
||||
}
|
||||
|
||||
if len(th) > 0 {
|
||||
if _, err := w.db.Model(&th).Insert(); err != nil {
|
||||
if _, err := w.db.Model(&th).Returning("NULL").Insert(); err != nil {
|
||||
return errors.Wrap(err, "couldn't insert tribes history")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ func (w *workerUpdateServerStats) update() error {
|
|||
}
|
||||
}(w.server)
|
||||
|
||||
if _, err := tx.Model(stats).Insert(); err != nil {
|
||||
if _, err := tx.Model(stats).Returning("NULL").Insert(); err != nil {
|
||||
return errors.Wrap(err, "couldn't insert server stats")
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ func Connect(cfg *Config) (*pg.DB, error) {
|
|||
if cfg != nil && cfg.LogQueries {
|
||||
db.AddQueryHook(querylogger.Logger{
|
||||
Log: log,
|
||||
MaxQueryLength: 5000,
|
||||
MaxQueryLength: 2000,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Reference in New Issue