Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: avoid updating unchanged records #96

Merged
merged 1 commit into from
Oct 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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