From cb7c549c7be2e4bb8fde4cac2949fb49e34e4f3b Mon Sep 17 00:00:00 2001 From: Alex Sahin Date: Wed, 26 Jun 2019 16:27:30 +0100 Subject: [PATCH] migrated to sync (#11407) --- app/channel.go | 4 ++-- store/sqlstore/user_store.go | 14 ++++++-------- store/store.go | 2 +- store/storetest/mocks/UserStore.go | 19 +++++++++++++------ 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/app/channel.go b/app/channel.go index 790c613bd9..2fa07a88b9 100644 --- a/app/channel.go +++ b/app/channel.go @@ -1841,8 +1841,8 @@ func (a *App) MarkChannelsAsViewed(channelIds []string, userId string, currentSe notify = user.NotifyProps[model.PUSH_NOTIFY_PROP] } if notify == model.USER_NOTIFY_ALL { - if result := <-a.Srv.Store.User().GetAnyUnreadPostCountForChannel(userId, channelId); result.Err == nil { - if result.Data.(int64) > 0 { + if count, err := a.Srv.Store.User().GetAnyUnreadPostCountForChannel(userId, channelId); err == nil { + if count > 0 { channelsToClearPushNotifications = append(channelsToClearPushNotifications, channelId) } } diff --git a/store/sqlstore/user_store.go b/store/sqlstore/user_store.go index 30289ce3bb..58abcc0a6d 100644 --- a/store/sqlstore/user_store.go +++ b/store/sqlstore/user_store.go @@ -1214,14 +1214,12 @@ func (us SqlUserStore) GetUnreadCountForChannel(userId string, channelId string) }) } -func (us SqlUserStore) GetAnyUnreadPostCountForChannel(userId string, channelId string) store.StoreChannel { - return store.Do(func(result *store.StoreResult) { - if count, err := us.GetReplica().SelectInt("SELECT SUM(c.TotalMsgCount - cm.MsgCount) FROM Channels c INNER JOIN ChannelMembers cm ON c.Id = cm.ChannelId AND cm.ChannelId = :ChannelId AND cm.UserId = :UserId", map[string]interface{}{"ChannelId": channelId, "UserId": userId}); err != nil { - result.Err = model.NewAppError("SqlUserStore.GetMentionCountForChannel", "store.sql_user.get_unread_count_for_channel.app_error", nil, err.Error(), http.StatusInternalServerError) - } else { - result.Data = count - } - }) +func (us SqlUserStore) GetAnyUnreadPostCountForChannel(userId string, channelId string) (int64, *model.AppError) { + count, err := us.GetReplica().SelectInt("SELECT SUM(c.TotalMsgCount - cm.MsgCount) FROM Channels c INNER JOIN ChannelMembers cm ON c.Id = cm.ChannelId AND cm.ChannelId = :ChannelId AND cm.UserId = :UserId", map[string]interface{}{"ChannelId": channelId, "UserId": userId}) + if err != nil { + return count, model.NewAppError("SqlUserStore.GetMentionCountForChannel", "store.sql_user.get_unread_count_for_channel.app_error", nil, err.Error(), http.StatusInternalServerError) + } + return count, nil } func (us SqlUserStore) Search(teamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) { diff --git a/store/store.go b/store/store.go index 0deb7d986b..e226527fe2 100644 --- a/store/store.go +++ b/store/store.go @@ -285,7 +285,7 @@ type UserStore interface { AnalyticsActiveCount(time int64) StoreChannel GetUnreadCount(userId string) (int64, error) GetUnreadCountForChannel(userId string, channelId string) StoreChannel - GetAnyUnreadPostCountForChannel(userId string, channelId string) StoreChannel + GetAnyUnreadPostCountForChannel(userId string, channelId string) (int64, *model.AppError) GetRecentlyActiveUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) StoreChannel GetNewUsersForTeam(teamId string, offset, limit int, viewRestrictions *model.ViewUsersRestrictions) ([]*model.User, *model.AppError) Search(teamId string, term string, options *model.UserSearchOptions) ([]*model.User, *model.AppError) diff --git a/store/storetest/mocks/UserStore.go b/store/storetest/mocks/UserStore.go index bdac6ffea9..3f01e25622 100644 --- a/store/storetest/mocks/UserStore.go +++ b/store/storetest/mocks/UserStore.go @@ -220,19 +220,26 @@ func (_m *UserStore) GetAllUsingAuthService(authService string) ([]*model.User, } // GetAnyUnreadPostCountForChannel provides a mock function with given fields: userId, channelId -func (_m *UserStore) GetAnyUnreadPostCountForChannel(userId string, channelId string) store.StoreChannel { +func (_m *UserStore) GetAnyUnreadPostCountForChannel(userId string, channelId string) (int64, *model.AppError) { ret := _m.Called(userId, channelId) - var r0 store.StoreChannel - if rf, ok := ret.Get(0).(func(string, string) store.StoreChannel); ok { + var r0 int64 + if rf, ok := ret.Get(0).(func(string, string) int64); ok { r0 = rf(userId, channelId) } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(store.StoreChannel) + r0 = ret.Get(0).(int64) + } + + var r1 *model.AppError + if rf, ok := ret.Get(1).(func(string, string) *model.AppError); ok { + r1 = rf(userId, channelId) + } else { + if ret.Get(1) != nil { + r1 = ret.Get(1).(*model.AppError) } } - return r0 + return r0, r1 } // GetByAuth provides a mock function with given fields: authData, authService