diff options
author | enahum <nahumhbl@gmail.com> | 2017-02-23 11:08:48 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-23 11:08:48 -0300 |
commit | 748a416961923932e9b2969beb2730ee8c240ea7 (patch) | |
tree | f6ab74d35fc1be8b9015f8a89e7ac6058ec1d4fe /store | |
parent | ca7d3b6e7bc2e52cf40180a462492313f298e760 (diff) | |
download | chat-748a416961923932e9b2969beb2730ee8c240ea7.tar.gz chat-748a416961923932e9b2969beb2730ee8c240ea7.tar.bz2 chat-748a416961923932e9b2969beb2730ee8c240ea7.zip |
PLT-3193 Add channel notification preferences for push and email notiā¦ (#5500)
* PLT-3193 Add channel notification preferences for push and email notifications
* unit tests, model validation and localization
* Feedback review
* Adding back allowFromCache check
* Setting push and email to use default settings
* Move props as constants
* address feedback
Diffstat (limited to 'store')
-rw-r--r-- | store/sql_channel_store.go | 68 | ||||
-rw-r--r-- | store/store.go | 2 |
2 files changed, 70 insertions, 0 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go index 03bc70c75..aac5bfed3 100644 --- a/store/sql_channel_store.go +++ b/store/sql_channel_store.go @@ -25,6 +25,9 @@ const ( ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SIZE = model.SESSION_CACHE_SIZE ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SEC = 900 // 15 mins + ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_SIZE = model.SESSION_CACHE_SIZE + ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_SEC = 1800 // 30 mins + CHANNEL_MEMBERS_COUNTS_CACHE_SIZE = model.CHANNEL_CACHE_SIZE CHANNEL_MEMBERS_COUNTS_CACHE_SEC = 1800 // 30 mins @@ -37,12 +40,14 @@ type SqlChannelStore struct { var channelMemberCountsCache = utils.NewLru(CHANNEL_MEMBERS_COUNTS_CACHE_SIZE) var allChannelMembersForUserCache = utils.NewLru(ALL_CHANNEL_MEMBERS_FOR_USER_CACHE_SIZE) +var allChannelMembersNotifyPropsForChannelCache = utils.NewLru(ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_SIZE) var channelCache = utils.NewLru(model.CHANNEL_CACHE_SIZE) var channelByNameCache = utils.NewLru(model.CHANNEL_CACHE_SIZE) func ClearChannelCaches() { channelMemberCountsCache.Purge() allChannelMembersForUserCache.Purge() + allChannelMembersNotifyPropsForChannelCache.Purge() channelCache.Purge() channelByNameCache.Purge() } @@ -919,6 +924,69 @@ func (s SqlChannelStore) GetAllChannelMembersForUser(userId string, allowFromCac return storeChannel } +func (us SqlChannelStore) InvalidateCacheForChannelMembersNotifyProps(channelId string) { + allChannelMembersNotifyPropsForChannelCache.Remove(channelId) +} + +type allChannelMemberNotifyProps struct { + UserId string + NotifyProps model.StringMap +} + +func (s SqlChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) StoreChannel { + storeChannel := make(StoreChannel, 1) + + go func() { + result := StoreResult{} + metrics := einterfaces.GetMetricsInterface() + + if allowFromCache { + if cacheItem, ok := allChannelMembersNotifyPropsForChannelCache.Get(channelId); ok { + if metrics != nil { + metrics.IncrementMemCacheHitCounter("All Channel Members Notify Props for Channel") + } + result.Data = cacheItem.(map[string]model.StringMap) + storeChannel <- result + close(storeChannel) + return + } else { + if metrics != nil { + metrics.IncrementMemCacheMissCounter("All Channel Members Notify Props for Channel") + } + } + } else { + if metrics != nil { + metrics.IncrementMemCacheMissCounter("All Channel Members Notify Props for Channel") + } + } + + var data []allChannelMemberNotifyProps + _, err := s.GetReplica().Select(&data, ` + SELECT ChannelMembers.UserId, ChannelMembers.NotifyProps + FROM Channels, ChannelMembers + WHERE Channels.Id = ChannelMembers.ChannelId AND ChannelMembers.ChannelId = :ChannelId`, map[string]interface{}{"ChannelId": channelId}) + + if err != nil { + result.Err = model.NewLocAppError("SqlChannelStore.GetAllChannelMembersPropsForChannel", "store.sql_channel.get_members.app_error", nil, "channelId="+channelId+", err="+err.Error()) + } else { + + props := make(map[string]model.StringMap) + for i := range data { + props[data[i].UserId] = data[i].NotifyProps + } + + result.Data = props + + allChannelMembersNotifyPropsForChannelCache.AddWithExpiresInSecs(channelId, props, ALL_CHANNEL_MEMBERS_NOTIFY_PROPS_FOR_CHANNEL_CACHE_SEC) + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} + func (us SqlChannelStore) InvalidateMemberCount(channelId string) { channelMemberCountsCache.Remove(channelId) } diff --git a/store/store.go b/store/store.go index d0c403460..3da331209 100644 --- a/store/store.go +++ b/store/store.go @@ -110,6 +110,8 @@ type ChannelStore interface { GetAllChannelMembersForUser(userId string, allowFromCache bool) StoreChannel InvalidateAllChannelMembersForUser(userId string) IsUserInChannelUseCache(userId string, channelId string) bool + GetAllChannelMembersNotifyPropsForChannel(channelId string, allowFromCache bool) StoreChannel + InvalidateCacheForChannelMembersNotifyProps(channelId string) GetMemberForPost(postId string, userId string) StoreChannel InvalidateMemberCount(channelId string) GetMemberCountFromCache(channelId string) int64 |