From 9d94869cc6a0fb9f051879437c104ccd76094380 Mon Sep 17 00:00:00 2001 From: Corey Hulen Date: Thu, 12 May 2016 18:36:30 -0700 Subject: Fixing issue with missing user (#2989) --- store/sql_user_store.go | 23 ++++++++++++++++++++++- store/sql_user_store_test.go | 24 ++++++++++++++++++++++++ store/store.go | 1 + 3 files changed, 47 insertions(+), 1 deletion(-) (limited to 'store') diff --git a/store/sql_user_store.go b/store/sql_user_store.go index 080d8d128..a6b706380 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -197,6 +197,27 @@ func (us SqlUserStore) UpdateLastPictureUpdate(userId string) StoreChannel { return storeChannel } +func (us SqlUserStore) UpdateUpdateAt(userId string) StoreChannel { + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + curTime := model.GetMillis() + + if _, err := us.GetMaster().Exec("UPDATE Users SET UpdateAt = :Time WHERE Id = :UserId", map[string]interface{}{"Time": curTime, "UserId": userId}); err != nil { + result.Err = model.NewLocAppError("SqlUserStore.UpdateUpdateAt", "store.sql_user.update_update.app_error", nil, "user_id="+userId) + } else { + result.Data = userId + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} + func (us SqlUserStore) UpdateLastPingAt(userId string, time int64) StoreChannel { storeChannel := make(StoreChannel) @@ -461,7 +482,7 @@ func (s SqlUserStore) GetEtagForDirectProfiles(userId string) StoreChannel { WHERE UserId = :UserId AND Category = 'direct_channel_show') - ORDER BY UpdateAt DESC + ORDER BY UpdateAt DESC LIMIT 1 `, map[string]interface{}{"UserId": userId}) if err != nil { result.Data = fmt.Sprintf("%v.%v", model.CurrentVersion, model.GetMillis()) diff --git a/store/sql_user_store_test.go b/store/sql_user_store_test.go index 5c33ea0f1..b6cfbb0ec 100644 --- a/store/sql_user_store_test.go +++ b/store/sql_user_store_test.go @@ -105,6 +105,30 @@ func TestUserStoreUpdate(t *testing.T) { } } +func TestUserStoreUpdateUpdateAt(t *testing.T) { + Setup() + + u1 := &model.User{} + u1.Email = model.NewId() + Must(store.User().Save(u1)) + Must(store.Team().SaveMember(&model.TeamMember{TeamId: model.NewId(), UserId: u1.Id})) + + time.Sleep(10 * time.Millisecond) + + if err := (<-store.User().UpdateUpdateAt(u1.Id)).Err; err != nil { + t.Fatal(err) + } + + if r1 := <-store.User().Get(u1.Id); r1.Err != nil { + t.Fatal(r1.Err) + } else { + if r1.Data.(*model.User).UpdateAt <= u1.UpdateAt { + t.Fatal("UpdateAt not updated correctly") + } + } + +} + func TestUserStoreUpdateLastPingAt(t *testing.T) { Setup() diff --git a/store/store.go b/store/store.go index 37aafdd4a..7f62fcd97 100644 --- a/store/store.go +++ b/store/store.go @@ -122,6 +122,7 @@ type UserStore interface { Save(user *model.User) StoreChannel Update(user *model.User, allowRoleUpdate bool) StoreChannel UpdateLastPictureUpdate(userId string) StoreChannel + UpdateUpdateAt(userId string) StoreChannel UpdateLastPingAt(userId string, time int64) StoreChannel UpdateLastActivityAt(userId string, time int64) StoreChannel UpdateUserAndSessionActivity(userId string, sessionId string, time int64) StoreChannel -- cgit v1.2.3-1-g7c22