summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
Diffstat (limited to 'store')
-rw-r--r--store/sql_store.go9
-rw-r--r--store/sql_webhook_store.go51
-rw-r--r--store/sql_webhook_store_test.go25
-rw-r--r--store/store.go2
4 files changed, 9 insertions, 78 deletions
diff --git a/store/sql_store.go b/store/sql_store.go
index a1a542691..c5bf840a1 100644
--- a/store/sql_store.go
+++ b/store/sql_store.go
@@ -32,7 +32,6 @@ import (
const (
INDEX_TYPE_FULL_TEXT = "full_text"
- INDEX_TYPE_PATTERN = "pattern"
INDEX_TYPE_DEFAULT = "default"
)
@@ -376,10 +375,6 @@ func (ss SqlStore) CreateFullTextIndexIfNotExists(indexName string, tableName st
ss.createIndexIfNotExists(indexName, tableName, columnName, INDEX_TYPE_FULL_TEXT)
}
-func (ss SqlStore) CreatePatternIndexIfNotExists(indexName string, tableName string, columnName string) {
- ss.createIndexIfNotExists(indexName, tableName, columnName, INDEX_TYPE_PATTERN)
-}
-
func (ss SqlStore) createIndexIfNotExists(indexName string, tableName string, columnName string, indexType string) {
if utils.Cfg.SqlSettings.DriverName == model.DATABASE_DRIVER_POSTGRES {
@@ -392,8 +387,6 @@ func (ss SqlStore) createIndexIfNotExists(indexName string, tableName string, co
query := ""
if indexType == INDEX_TYPE_FULL_TEXT {
query = "CREATE INDEX " + indexName + " ON " + tableName + " USING gin(to_tsvector('english', " + columnName + "))"
- } else if indexType == INDEX_TYPE_PATTERN {
- query = "CREATE INDEX " + indexName + " ON " + tableName + " (" + columnName + " text_pattern_ops)"
} else {
query = "CREATE INDEX " + indexName + " ON " + tableName + " (" + columnName + ")"
}
@@ -418,7 +411,7 @@ func (ss SqlStore) createIndexIfNotExists(indexName string, tableName string, co
}
fullTextIndex := ""
- if indexType == INDEX_TYPE_FULL_TEXT || indexType == INDEX_TYPE_PATTERN {
+ if indexType == INDEX_TYPE_FULL_TEXT {
fullTextIndex = " FULLTEXT "
}
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
diff --git a/store/sql_webhook_store_test.go b/store/sql_webhook_store_test.go
index 6098b2131..1fb990f3e 100644
--- a/store/sql_webhook_store_test.go
+++ b/store/sql_webhook_store_test.go
@@ -201,27 +201,18 @@ func TestWebhookStoreGetOutgoingByCreator(t *testing.T) {
}
}
-func TestWebhookStoreGetOutgoingByTriggerWord(t *testing.T) {
+func TestWebhookStoreGetOutgoingByTeam(t *testing.T) {
Setup()
o1 := &model.OutgoingWebhook{}
+ o1.ChannelId = model.NewId()
o1.CreatorId = model.NewId()
o1.TeamId = model.NewId()
- o1.TriggerWords = []string{"trigger"}
o1.CallbackURLs = []string{"http://nowhere.com/"}
o1 = (<-store.Webhook().SaveOutgoing(o1)).Data.(*model.OutgoingWebhook)
- o2 := &model.OutgoingWebhook{}
- o2.CreatorId = model.NewId()
- o2.TeamId = o1.TeamId
- o2.ChannelId = model.NewId()
- o2.TriggerWords = []string{"trigger"}
- o2.CallbackURLs = []string{"http://nowhere.com/"}
-
- o2 = (<-store.Webhook().SaveOutgoing(o2)).Data.(*model.OutgoingWebhook)
-
- if r1 := <-store.Webhook().GetOutgoingByTriggerWord(o1.TeamId, "", "trigger"); r1.Err != nil {
+ if r1 := <-store.Webhook().GetOutgoingByTeam(o1.TeamId); r1.Err != nil {
t.Fatal(r1.Err)
} else {
if r1.Data.([]*model.OutgoingWebhook)[0].CreateAt != o1.CreateAt {
@@ -229,15 +220,7 @@ func TestWebhookStoreGetOutgoingByTriggerWord(t *testing.T) {
}
}
- if r1 := <-store.Webhook().GetOutgoingByTriggerWord(o2.TeamId, o2.ChannelId, "trigger"); r1.Err != nil {
- t.Fatal(r1.Err)
- } else {
- if len(r1.Data.([]*model.OutgoingWebhook)) != 2 {
- t.Fatal("wrong number of webhooks returned")
- }
- }
-
- if result := <-store.Webhook().GetOutgoingByTriggerWord(o1.TeamId, "", "blargh"); result.Err != nil {
+ if result := <-store.Webhook().GetOutgoingByTeam("123"); result.Err != nil {
t.Fatal(result.Err)
} else {
if len(result.Data.([]*model.OutgoingWebhook)) != 0 {
diff --git a/store/store.go b/store/store.go
index 2a099975c..70980a15c 100644
--- a/store/store.go
+++ b/store/store.go
@@ -154,7 +154,7 @@ type WebhookStore interface {
GetOutgoing(id string) StoreChannel
GetOutgoingByCreator(userId string) StoreChannel
GetOutgoingByChannel(channelId string) StoreChannel
- GetOutgoingByTriggerWord(teamId, channelId, triggerWord string) StoreChannel
+ GetOutgoingByTeam(teamId string) StoreChannel
DeleteOutgoing(webhookId string, time int64) StoreChannel
UpdateOutgoing(hook *model.OutgoingWebhook) StoreChannel
}