diff options
Diffstat (limited to 'store')
-rw-r--r-- | store/sql_channel_store.go | 20 | ||||
-rw-r--r-- | store/sql_channel_store_test.go | 8 | ||||
-rw-r--r-- | store/store.go | 1 |
3 files changed, 25 insertions, 4 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go index fc4e19442..a9f99bd67 100644 --- a/store/sql_channel_store.go +++ b/store/sql_channel_store.go @@ -542,6 +542,26 @@ func (s SqlChannelStore) GetMember(channelId string, userId string) StoreChannel return storeChannel } +func (s SqlChannelStore) GetMemberCount(channelId string) StoreChannel { + storeChannel := make(StoreChannel) + + go func() { + result := StoreResult{} + + count, err := s.GetReplica().SelectInt("SELECT count(*) FROM ChannelMembers WHERE ChannelId = :ChannelId", map[string]interface{}{"ChannelId": channelId}) + if err != nil { + result.Err = model.NewAppError("SqlChannelStore.GetMemberCount", "We couldn't get the channel member count", "channel_id="+channelId+", "+err.Error()) + } else { + result.Data = count + } + + storeChannel <- result + close(storeChannel) + }() + + return storeChannel +} + func (s SqlChannelStore) GetExtraMembers(channelId string, limit int) StoreChannel { storeChannel := make(StoreChannel) diff --git a/store/sql_channel_store_test.go b/store/sql_channel_store_test.go index f6a0fb713..8662fcbd3 100644 --- a/store/sql_channel_store_test.go +++ b/store/sql_channel_store_test.go @@ -339,15 +339,15 @@ func TestChannelMemberStore(t *testing.T) { t.Fatal("Member update time incorrect") } - members := (<-store.Channel().GetMembers(o1.ChannelId)).Data.([]model.ChannelMember) - if len(members) != 2 { + count := (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64) + if count != 2 { t.Fatal("should have saved 2 members") } Must(store.Channel().RemoveMember(o2.ChannelId, o2.UserId)) - members = (<-store.Channel().GetMembers(o1.ChannelId)).Data.([]model.ChannelMember) - if len(members) != 1 { + count = (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64) + if count != 1 { t.Fatal("should have removed 1 member") } diff --git a/store/store.go b/store/store.go index ce4d90883..13b59b582 100644 --- a/store/store.go +++ b/store/store.go @@ -70,6 +70,7 @@ type ChannelStore interface { UpdateMember(member *model.ChannelMember) StoreChannel GetMembers(channelId string) StoreChannel GetMember(channelId string, userId string) StoreChannel + GetMemberCount(channelId string) StoreChannel RemoveMember(channelId string, userId string) StoreChannel GetExtraMembers(channelId string, limit int) StoreChannel CheckPermissionsTo(teamId string, channelId string, userId string) StoreChannel |