summaryrefslogtreecommitdiffstats
path: root/store/sql_channel_store.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2015-08-14 08:35:19 -0400
committerChristopher Speller <crspeller@gmail.com>2015-08-14 08:35:19 -0400
commita8930cbabec21635a10e8cac4d2c0c79867f283d (patch)
treea622f8d94fa1b60753896640c1f8c1a5ebaf48e2 /store/sql_channel_store.go
parentb1d37e9c385f0d3e9bddd9dffe1570574dcdcab6 (diff)
parent2485b87b28a7fed1996d627b48dcd94f19002fc8 (diff)
downloadchat-a8930cbabec21635a10e8cac4d2c0c79867f283d.tar.gz
chat-a8930cbabec21635a10e8cac4d2c0c79867f283d.tar.bz2
chat-a8930cbabec21635a10e8cac4d2c0c79867f283d.zip
Merge pull request #365 from mattermost/mm-1700
MM-1700 don't pull all channel data all the time
Diffstat (limited to 'store/sql_channel_store.go')
-rw-r--r--store/sql_channel_store.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go
index cac5c681b..b8bf8b5ac 100644
--- a/store/sql_channel_store.go
+++ b/store/sql_channel_store.go
@@ -281,6 +281,41 @@ func (s SqlChannelStore) GetMoreChannels(teamId string, userId string) StoreChan
return storeChannel
}
+type channelIdWithCountAndUpdateAt struct {
+ Id string
+ TotalMsgCount int64
+ UpdateAt int64
+}
+
+func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) StoreChannel {
+ storeChannel := make(StoreChannel)
+
+ go func() {
+ result := StoreResult{}
+
+ var data []channelIdWithCountAndUpdateAt
+ _, err := s.GetReplica().Select(&data, "SELECT Id, TotalMsgCount, UpdateAt FROM Channels WHERE Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = :UserId) AND TeamId = :TeamId AND DeleteAt = 0 ORDER BY DisplayName", map[string]interface{}{"TeamId": teamId, "UserId": userId})
+
+ if err != nil {
+ result.Err = model.NewAppError("SqlChannelStore.GetChannelCounts", "We couldn't get the channel counts", "teamId="+teamId+", userId="+userId+", err="+err.Error())
+ } else {
+ counts := &model.ChannelCounts{Counts: make(map[string]int64), UpdateTimes: make(map[string]int64)}
+ for i := range data {
+ v := data[i]
+ counts.Counts[v.Id] = v.TotalMsgCount
+ counts.UpdateTimes[v.Id] = v.UpdateAt
+ }
+
+ result.Data = counts
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
func (s SqlChannelStore) GetByName(teamId string, name string) StoreChannel {
storeChannel := make(StoreChannel)