summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
author=Corey Hulen <corey@hulen.com>2015-12-15 11:05:40 -0800
committer=Corey Hulen <corey@hulen.com>2015-12-15 11:05:40 -0800
commit944f884a0557f50704fccc530810f4d99a17de49 (patch)
treea75aae99b0b91daf8053a7810f195cb34ef35ab4 /store
parentba149bd971a5111808a7aaa6478c8de885b9f6ae (diff)
downloadchat-944f884a0557f50704fccc530810f4d99a17de49.tar.gz
chat-944f884a0557f50704fccc530810f4d99a17de49.tar.bz2
chat-944f884a0557f50704fccc530810f4d99a17de49.zip
Fixing channel limit
Diffstat (limited to 'store')
-rw-r--r--store/sql_channel_store.go16
-rw-r--r--store/sql_channel_store_test.go2
2 files changed, 10 insertions, 8 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go
index b68774189..c9e0d113f 100644
--- a/store/sql_channel_store.go
+++ b/store/sql_channel_store.go
@@ -145,18 +145,20 @@ func (s SqlChannelStore) saveChannelT(transaction *gorp.Transaction, channel *mo
return result
}
- if count, err := transaction.SelectInt("SELECT COUNT(0) FROM Channels WHERE TeamId = :TeamId AND DeleteAt = 0 AND (Type = 'O' OR Type = 'P')", map[string]interface{}{"TeamId": channel.TeamId}); err != nil {
- result.Err = model.NewAppError("SqlChannelStore.Save", "Failed to get current channel count", "teamId="+channel.TeamId+", "+err.Error())
- return result
- } else if count > 150 {
- result.Err = model.NewAppError("SqlChannelStore.Save", "You've reached the limit of the number of allowed channels.", "teamId="+channel.TeamId)
- return result
+ if channel.Type != model.CHANNEL_DIRECT {
+ if count, err := transaction.SelectInt("SELECT COUNT(0) FROM Channels WHERE TeamId = :TeamId AND DeleteAt = 0 AND (Type = 'O' OR Type = 'P')", map[string]interface{}{"TeamId": channel.TeamId}); err != nil {
+ result.Err = model.NewAppError("SqlChannelStore.Save", "Failed to get current channel count", "teamId="+channel.TeamId+", "+err.Error())
+ return result
+ } else if count > 1000 {
+ result.Err = model.NewAppError("SqlChannelStore.Save", "You've reached the limit of the number of allowed channels.", "teamId="+channel.TeamId)
+ return result
+ }
}
if err := transaction.Insert(channel); err != nil {
if IsUniqueConstraintError(err.Error(), "Name", "channels_name_teamid_key") {
dupChannel := model.Channel{}
- s.GetReplica().SelectOne(&dupChannel, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Name = :Name AND DeleteAt > 0", map[string]interface{}{"TeamId": channel.TeamId, "Name": channel.Name})
+ s.GetMaster().SelectOne(&dupChannel, "SELECT * FROM Channels WHERE TeamId = :TeamId AND Name = :Name AND DeleteAt > 0", map[string]interface{}{"TeamId": channel.TeamId, "Name": channel.Name})
if dupChannel.DeleteAt > 0 {
result.Err = model.NewAppError("SqlChannelStore.Update", "A channel with that URL was previously created", "id="+channel.Id+", "+err.Error())
} else {
diff --git a/store/sql_channel_store_test.go b/store/sql_channel_store_test.go
index 695991bf7..8b22fbb7a 100644
--- a/store/sql_channel_store_test.go
+++ b/store/sql_channel_store_test.go
@@ -41,7 +41,7 @@ func TestChannelStoreSave(t *testing.T) {
}
o1.Type = model.CHANNEL_OPEN
- for i := 0; i < 150; i++ {
+ for i := 0; i < 1000; i++ {
o1.Id = ""
o1.Name = "a" + model.NewId() + "b"
if err := (<-store.Channel().Save(&o1)).Err; err != nil {