From 49504b6815cbf83df15a253092db2e00315f9291 Mon Sep 17 00:00:00 2001 From: Manfred Touron Date: Sat, 6 Oct 2018 13:12:29 +0200 Subject: [PATCH] feat: avoid updating unchanged records --- cmd_airtable.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/cmd_airtable.go b/cmd_airtable.go index 7a5666edf..35fd12572 100644 --- a/cmd_airtable.go +++ b/cmd_airtable.go @@ -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") @@ -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,