Skip to content

Commit

Permalink
Merge pull request #96 from moul/dev/moul/airtable-changed
Browse files Browse the repository at this point in the history
feat: avoid updating unchanged records
  • Loading branch information
moul authored Oct 6, 2018
2 parents 8d3fb83 + 49504b6 commit 2b777fc
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cmd_airtable.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ func airtableSync(opts *airtableOptions) error {
if issue.Hidden {
continue
}
// FIXME: check if entry changed before updating

if issue.ToAirtableRecord().Fields.Equals(record.Fields) {
continue
}

logger().Debug("updating airtable record", zap.String("ID", issue.URL))
if err := at.UpdateRecord(opts.AirtableTableName, record.ID, issue.ToAirtableRecord().Fields.Map(), &record); err != nil {
return errors.Wrap(err, "failed to update record")
Expand Down Expand Up @@ -137,6 +141,18 @@ type airtableIssue struct {
Title string
}

func (ai airtableIssue) Equals(other airtableIssue) bool {
return ai.ID == other.ID &&
ai.Created.Truncate(time.Millisecond).UTC() == other.Created.Truncate(time.Millisecond).UTC() &&
ai.Updated.Truncate(time.Millisecond).UTC() == other.Updated.Truncate(time.Millisecond).UTC() &&
ai.Title == other.Title
}

func (ai airtableIssue) String() string {
out, _ := json.Marshal(ai)
return string(out)
}

func (a airtableIssue) Map() map[string]interface{} {
return map[string]interface{}{
"ID": a.ID,
Expand Down

0 comments on commit 2b777fc

Please sign in to comment.