Avoid updating records when then didn't actually change
parent
9c51a4621f
commit
0cc11e75b2
|
@ -232,13 +232,17 @@ retry:
|
||||||
for _, batch := range splitInBatshes(recs, 500) {
|
for _, batch := range splitInBatshes(recs, 500) {
|
||||||
result := p.db.Model(&repo.Record{}).
|
result := p.db.Model(&repo.Record{}).
|
||||||
Clauses(clause.OnConflict{
|
Clauses(clause.OnConflict{
|
||||||
Where: clause.Where{Exprs: []clause.Expression{clause.Or(
|
Where: clause.Where{Exprs: []clause.Expression{
|
||||||
clause.Eq{Column: clause.Column{Name: "at_rev", Table: "records"}, Value: nil},
|
clause.Neq{
|
||||||
clause.Eq{Column: clause.Column{Name: "at_rev", Table: "records"}, Value: ""},
|
Column: clause.Column{Name: "content", Table: "records"},
|
||||||
clause.Lt{
|
Value: clause.Column{Name: "content", Table: "excluded"}},
|
||||||
Column: clause.Column{Name: "at_rev", Table: "records"},
|
clause.Or(
|
||||||
Value: clause.Column{Name: "at_rev", Table: "excluded"}},
|
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"}),
|
DoUpdates: clause.AssignmentColumns([]string{"content", "at_rev"}),
|
||||||
Columns: []clause.Column{{Name: "repo"}, {Name: "collection"}, {Name: "rkey"}}}).
|
Columns: []clause.Column{{Name: "repo"}, {Name: "collection"}, {Name: "rkey"}}}).
|
||||||
Create(batch)
|
Create(batch)
|
||||||
|
|
|
@ -33,7 +33,7 @@ type Repo struct {
|
||||||
type Record struct {
|
type Record struct {
|
||||||
ID models.ID `gorm:"primarykey"`
|
ID models.ID `gorm:"primarykey"`
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time `gorm:"autoUpdateTime:false"`
|
||||||
Repo models.ID `gorm:"index:idx_repo_record_key,unique,priority:1;not null;index:idx_repo_rev"`
|
Repo models.ID `gorm:"index:idx_repo_record_key,unique,priority:1;not null;index:idx_repo_rev"`
|
||||||
Collection string `gorm:"index:idx_repo_record_key,unique,priority:2;not null"`
|
Collection string `gorm:"index:idx_repo_record_key,unique,priority:2;not null"`
|
||||||
Rkey string `gorm:"index:idx_repo_record_key,unique,priority:3"`
|
Rkey string `gorm:"index:idx_repo_record_key,unique,priority:3"`
|
||||||
|
|
Loading…
Reference in New Issue