Skip to content

Commit

Permalink
Merge pull request rapidpro#330 from nyaruka/last_seen_tweak
Browse files Browse the repository at this point in the history
Remove protection for overwriting last_seen_on with older values
  • Loading branch information
rowanseymour authored Aug 6, 2020
2 parents a816300 + 56e96c3 commit 5e07653
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 9 deletions.
2 changes: 1 addition & 1 deletion models/contacts.go
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ func UpdateContactModifiedOn(ctx context.Context, tx Queryer, contactIDs []Conta

// UpdateContactLastSeenOn updates last seen on (and modified on) on the passed in contact
func UpdateContactLastSeenOn(ctx context.Context, tx Queryer, contactID ContactID, lastSeenOn time.Time) error {
_, err := tx.ExecContext(ctx, `UPDATE contacts_contact SET last_seen_on = $2, modified_on = NOW() WHERE id = $1 AND last_seen_on IS NULL OR last_seen_on < $2`, contactID, lastSeenOn)
_, err := tx.ExecContext(ctx, `UPDATE contacts_contact SET last_seen_on = $2, modified_on = NOW() WHERE id = $1`, contactID, lastSeenOn)
return err
}

Expand Down
8 changes: 0 additions & 8 deletions models/contacts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,6 @@ func TestUpdateContactLastSeenAndModifiedOn(t *testing.T) {
require.NoError(t, err)
assert.True(t, t2.Equal(*cathy.LastSeenOn()))
assert.True(t, cathy.ModifiedOn().After(t2))

// can't accidently overwrite a newer date
err = cathy.UpdateLastSeenOn(ctx, db, time.Date(2010, 1, 1, 12, 0, 0, 0, time.UTC))
require.NoError(t, err)

cathy, err = LoadContact(ctx, db, oa, CathyID)
require.NoError(t, err)
assert.True(t, t2.Equal(*cathy.LastSeenOn()))
}

func TestUpdateContactModifiedBy(t *testing.T) {
Expand Down

0 comments on commit 5e07653

Please sign in to comment.