summaryrefslogtreecommitdiffstats
path: root/store/sql_webhook_store.go
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2015-10-16 11:17:24 -0400
committerJoramWilander <jwawilander@gmail.com>2015-10-19 09:00:30 -0400
commitf24ea30a75ad52b695f5f275139af1c0495624ac (patch)
tree74ea933bb3e67019a24d168b2f55e61800c1c243 /store/sql_webhook_store.go
parent9de8bc4727132f8ec5d67f9d3e8a9642774c296c (diff)
downloadchat-f24ea30a75ad52b695f5f275139af1c0495624ac.tar.gz
chat-f24ea30a75ad52b695f5f275139af1c0495624ac.tar.bz2
chat-f24ea30a75ad52b695f5f275139af1c0495624ac.zip
Refactor to hit database less often.
Diffstat (limited to 'store/sql_webhook_store.go')
-rw-r--r--store/sql_webhook_store.go51
1 files changed, 3 insertions, 48 deletions
diff --git a/store/sql_webhook_store.go b/store/sql_webhook_store.go
index 68a3236eb..14469e2e7 100644
--- a/store/sql_webhook_store.go
+++ b/store/sql_webhook_store.go
@@ -5,7 +5,6 @@ package store
import (
"github.com/mattermost/platform/model"
- "github.com/mattermost/platform/utils"
)
type SqlWebhookStore struct {
@@ -42,8 +41,6 @@ func (s SqlWebhookStore) CreateIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_incoming_webhook_user_id", "IncomingWebhooks", "UserId")
s.CreateIndexIfNotExists("idx_incoming_webhook_team_id", "IncomingWebhooks", "TeamId")
s.CreateIndexIfNotExists("idx_outgoing_webhook_channel_id", "OutgoingWebhooks", "ChannelId")
-
- s.CreatePatternIndexIfNotExists("idx_outgoing_webhook_trigger_txt", "OutgoingWebhooks", "TriggerWords")
}
func (s SqlWebhookStore) SaveIncoming(webhook *model.IncomingWebhook) StoreChannel {
@@ -237,7 +234,7 @@ func (s SqlWebhookStore) GetOutgoingByChannel(channelId string) StoreChannel {
return storeChannel
}
-func (s SqlWebhookStore) GetOutgoingByTriggerWord(teamId, channelId, triggerWord string) StoreChannel {
+func (s SqlWebhookStore) GetOutgoingByTeam(teamId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -245,50 +242,8 @@ func (s SqlWebhookStore) GetOutgoingByTriggerWord(teamId, channelId, triggerWord
var webhooks []*model.OutgoingWebhook
- var err error
-
- if utils.Cfg.SqlSettings.DriverName == "postgres" {
-
- searchQuery := `SELECT
- *
- FROM
- OutgoingWebhooks
- WHERE
- DeleteAt = 0
- AND TeamId = $1
- AND TriggerWords LIKE '%' || $2 || '%'`
-
- if len(channelId) != 0 {
- searchQuery += " AND (ChannelId = $3 OR ChannelId = '')"
- _, err = s.GetReplica().Select(&webhooks, searchQuery, teamId, triggerWord, channelId)
- } else {
- searchQuery += " AND ChannelId = ''"
- _, err = s.GetReplica().Select(&webhooks, searchQuery, teamId, triggerWord)
- }
-
- } else if utils.Cfg.SqlSettings.DriverName == "mysql" {
- searchQuery := `SELECT
- *
- FROM
- OutgoingWebhooks
- WHERE
- DeleteAt = 0
- AND TeamId = ?
- AND MATCH (TriggerWords) AGAINST (? IN BOOLEAN MODE)`
-
- triggerWord = "+" + triggerWord
-
- if len(channelId) != 0 {
- searchQuery += " AND (ChannelId = ? OR ChannelId = '')"
- _, err = s.GetReplica().Select(&webhooks, searchQuery, teamId, triggerWord, channelId)
- } else {
- searchQuery += " AND ChannelId = ''"
- _, err = s.GetReplica().Select(&webhooks, searchQuery, teamId, triggerWord)
- }
- }
-
- if err != nil {
- result.Err = model.NewAppError("SqlPostStore.GetOutgoingByTriggerWord", "We encounted an error while getting the outgoing webhooks by trigger word", "teamId="+teamId+", channelId="+channelId+", triggerWord="+triggerWord+", err="+err.Error())
+ if _, err := s.GetReplica().Select(&webhooks, "SELECT * FROM OutgoingWebhooks WHERE TeamId = :TeamId AND DeleteAt = 0", map[string]interface{}{"TeamId": teamId}); err != nil {
+ result.Err = model.NewAppError("SqlWebhookStore.GetOutgoingByTeam", "We couldn't get the webhooks", "teamId="+teamId+", err="+err.Error())
}
result.Data = webhooks