Avoid updating records when then didn't actually change
This commit is contained in:
parent
9c51a4621f
commit
0cc11e75b2
2 changed files with 12 additions and 8 deletions
|
@ -232,13 +232,17 @@ retry:
|
|||
for _, batch := range splitInBatshes(recs, 500) {
|
||||
result := p.db.Model(&repo.Record{}).
|
||||
Clauses(clause.OnConflict{
|
||||
Where: clause.Where{Exprs: []clause.Expression{clause.Or(
|
||||
clause.Eq{Column: clause.Column{Name: "at_rev", Table: "records"}, Value: nil},
|
||||
clause.Eq{Column: clause.Column{Name: "at_rev", Table: "records"}, Value: ""},
|
||||
clause.Lt{
|
||||
Column: clause.Column{Name: "at_rev", Table: "records"},
|
||||
Value: clause.Column{Name: "at_rev", Table: "excluded"}},
|
||||
)}},
|
||||
Where: clause.Where{Exprs: []clause.Expression{
|
||||
clause.Neq{
|
||||
Column: clause.Column{Name: "content", Table: "records"},
|
||||
Value: clause.Column{Name: "content", Table: "excluded"}},
|
||||
clause.Or(
|
||||
clause.Eq{Column: clause.Column{Name: "at_rev", Table: "records"}, Value: nil},
|
||||
clause.Eq{Column: clause.Column{Name: "at_rev", Table: "records"}, Value: ""},
|
||||
clause.Lt{
|
||||
Column: clause.Column{Name: "at_rev", Table: "records"},
|
||||
Value: clause.Column{Name: "at_rev", Table: "excluded"}},
|
||||
)}},
|
||||
DoUpdates: clause.AssignmentColumns([]string{"content", "at_rev"}),
|
||||
Columns: []clause.Column{{Name: "repo"}, {Name: "collection"}, {Name: "rkey"}}}).
|
||||
Create(batch)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue