summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
authorJoramWilander <jwawilander@gmail.com>2018-06-27 16:56:50 -0400
committerJoramWilander <jwawilander@gmail.com>2018-06-27 16:56:50 -0400
commit88c5e469ca869d9e8ceadb0f2b03e86005102f24 (patch)
treebbb1b4cc1312879476f222940651e4d3e763da9e /store
parentd7976549a0b45a42c04ac043a15677b7ca1228e9 (diff)
parent437f9f5b64ddb4e1f84e6c4e993120d074001777 (diff)
downloadchat-88c5e469ca869d9e8ceadb0f2b03e86005102f24.tar.gz
chat-88c5e469ca869d9e8ceadb0f2b03e86005102f24.tar.bz2
chat-88c5e469ca869d9e8ceadb0f2b03e86005102f24.zip
Merge branch 'master' into plugins-2
Diffstat (limited to 'store')
-rw-r--r--store/layered_store.go8
-rw-r--r--store/sqlstore/channel_store.go6
-rw-r--r--store/sqlstore/store.go2
-rw-r--r--store/sqlstore/supplier.go11
-rw-r--r--store/sqlstore/upgrade.go2
-rw-r--r--store/store.go2
-rw-r--r--store/storetest/channel_store.go42
-rw-r--r--store/storetest/mocks/LayeredStoreDatabaseLayer.go10
-rw-r--r--store/storetest/mocks/SqlStore.go10
-rw-r--r--store/storetest/mocks/Store.go10
-rw-r--r--store/storetest/store.go2
11 files changed, 101 insertions, 4 deletions
diff --git a/store/layered_store.go b/store/layered_store.go
index 851d7536c..6587868d6 100644
--- a/store/layered_store.go
+++ b/store/layered_store.go
@@ -181,6 +181,14 @@ func (s *LayeredStore) Close() {
s.DatabaseLayer.Close()
}
+func (s *LayeredStore) LockToMaster() {
+ s.DatabaseLayer.LockToMaster()
+}
+
+func (s *LayeredStore) UnlockFromMaster() {
+ s.DatabaseLayer.UnlockFromMaster()
+}
+
func (s *LayeredStore) DropAllTables() {
s.DatabaseLayer.DropAllTables()
}
diff --git a/store/sqlstore/channel_store.go b/store/sqlstore/channel_store.go
index eb88bc42a..e062d41d1 100644
--- a/store/sqlstore/channel_store.go
+++ b/store/sqlstore/channel_store.go
@@ -298,7 +298,7 @@ func (s SqlChannelStore) CreateIndexesIfNotExists() {
s.CreateIndexIfNotExists("idx_channelmembers_channel_id", "ChannelMembers", "ChannelId")
s.CreateIndexIfNotExists("idx_channelmembers_user_id", "ChannelMembers", "UserId")
- s.CreateFullTextIndexIfNotExists("idx_channels_txt", "Channels", "Name, DisplayName")
+ s.CreateFullTextIndexIfNotExists("idx_channel_search_txt", "Channels", "Name, DisplayName, Purpose")
}
func (s SqlChannelStore) Save(channel *model.Channel, maxChannelsPerTeam int64) store.StoreChannel {
@@ -1573,7 +1573,7 @@ func (s SqlChannelStore) SearchMore(userId string, teamId string, term string) s
func (s SqlChannelStore) buildLIKEClause(term string) (likeClause, likeTerm string) {
likeTerm = term
- searchColumns := "Name, DisplayName"
+ searchColumns := "Name, DisplayName, Purpose"
// These chars must be removed from the like query.
for _, c := range ignoreLikeSearchChar {
@@ -1608,7 +1608,7 @@ func (s SqlChannelStore) buildFulltextClause(term string) (fulltextClause, fullt
// Copy the terms as we will need to prepare them differently for each search type.
fulltextTerm = term
- searchColumns := "Name, DisplayName"
+ searchColumns := "Name, DisplayName, Purpose"
// These chars must be treated as spaces in the fulltext query.
for _, c := range spaceFulltextSearchChar {
diff --git a/store/sqlstore/store.go b/store/sqlstore/store.go
index fc7b3be18..500f98235 100644
--- a/store/sqlstore/store.go
+++ b/store/sqlstore/store.go
@@ -65,6 +65,8 @@ type SqlStore interface {
RemoveIndexIfExists(indexName string, tableName string) bool
GetAllConns() []*gorp.DbMap
Close()
+ LockToMaster()
+ UnlockFromMaster()
Team() store.TeamStore
Channel() store.ChannelStore
Post() store.PostStore
diff --git a/store/sqlstore/supplier.go b/store/sqlstore/supplier.go
index 02a3cef7f..1e6bdcba1 100644
--- a/store/sqlstore/supplier.go
+++ b/store/sqlstore/supplier.go
@@ -105,6 +105,7 @@ type SqlSupplier struct {
searchReplicas []*gorp.DbMap
oldStores SqlSupplierOldStores
settings *model.SqlSettings
+ lockedToMaster bool
}
func NewSqlSupplier(settings model.SqlSettings, metrics einterfaces.MetricsInterface) *SqlSupplier {
@@ -283,7 +284,7 @@ func (ss *SqlSupplier) GetSearchReplica() *gorp.DbMap {
}
func (ss *SqlSupplier) GetReplica() *gorp.DbMap {
- if len(ss.settings.DataSourceReplicas) == 0 {
+ if len(ss.settings.DataSourceReplicas) == 0 || ss.lockedToMaster {
return ss.GetMaster()
}
@@ -801,6 +802,14 @@ func (ss *SqlSupplier) Close() {
}
}
+func (ss *SqlSupplier) LockToMaster() {
+ ss.lockedToMaster = true
+}
+
+func (ss *SqlSupplier) UnlockFromMaster() {
+ ss.lockedToMaster = false
+}
+
func (ss *SqlSupplier) Team() store.TeamStore {
return ss.oldStores.team
}
diff --git a/store/sqlstore/upgrade.go b/store/sqlstore/upgrade.go
index 65c2c11e2..fc2d53235 100644
--- a/store/sqlstore/upgrade.go
+++ b/store/sqlstore/upgrade.go
@@ -446,6 +446,8 @@ func UpgradeDatabaseToVersion50(sqlStore SqlStore) {
sqlStore.GetMaster().Exec("UPDATE Roles SET SchemeManaged=false WHERE Name NOT IN ('system_user', 'system_admin', 'team_user', 'team_admin', 'channel_user', 'channel_admin')")
sqlStore.CreateColumnIfNotExists("IncomingWebhooks", "ChannelLocked", "boolean", "boolean", "0")
+ sqlStore.RemoveIndexIfExists("idx_channels_txt", "Channels")
+
saveSchemaVersion(sqlStore, VERSION_5_0_0)
}
}
diff --git a/store/store.go b/store/store.go
index bb967e614..203c637ff 100644
--- a/store/store.go
+++ b/store/store.go
@@ -67,6 +67,8 @@ type Store interface {
Plugin() PluginStore
MarkSystemRanUnitTests()
Close()
+ LockToMaster()
+ UnlockFromMaster()
DropAllTables()
TotalMasterDbConnections() int
TotalReadDbConnections() int
diff --git a/store/storetest/channel_store.go b/store/storetest/channel_store.go
index ecec7fab9..b033e9c98 100644
--- a/store/storetest/channel_store.go
+++ b/store/storetest/channel_store.go
@@ -1708,6 +1708,14 @@ func testChannelStoreSearchMore(t *testing.T, ss store.Store) {
o8.Type = model.CHANNEL_PRIVATE
store.Must(ss.Channel().Save(&o8, -1))
+ o9 := model.Channel{}
+ o9.TeamId = o1.TeamId
+ o9.DisplayName = "Channel With Purpose"
+ o9.Purpose = "This can now be searchable!"
+ o9.Name = "with-purpose"
+ o9.Type = model.CHANNEL_OPEN
+ store.Must(ss.Channel().Save(&o9, -1))
+
if result := <-ss.Channel().SearchMore(m1.UserId, o1.TeamId, "ChannelA"); result.Err != nil {
t.Fatal(result.Err)
} else {
@@ -1773,6 +1781,19 @@ func testChannelStoreSearchMore(t *testing.T, ss store.Store) {
}
}
+ if result := <-ss.Channel().SearchMore(m1.UserId, o1.TeamId, "now searchable"); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ if len(*channels) != 1 {
+ t.Fatal("should return 1 channel")
+ }
+
+ if (*channels)[0].Name != o9.Name {
+ t.Fatal("wrong channel returned")
+ }
+ }
+
/*
// Disabling this check as it will fail on PostgreSQL as we have "liberalised" channel matching to deal with
// Full-Text Stemming Limitations.
@@ -1884,6 +1905,14 @@ func testChannelStoreSearchInTeam(t *testing.T, ss store.Store) {
o11.Type = model.CHANNEL_OPEN
store.Must(ss.Channel().Save(&o11, -1))
+ o12 := model.Channel{}
+ o12.TeamId = o1.TeamId
+ o12.DisplayName = "Channel With Purpose"
+ o12.Purpose = "This can now be searchable!"
+ o12.Name = "with-purpose"
+ o12.Type = model.CHANNEL_OPEN
+ store.Must(ss.Channel().Save(&o12, -1))
+
for name, search := range map[string]func(teamId string, term string) store.StoreChannel{
"AutocompleteInTeam": ss.Channel().AutocompleteInTeam,
"SearchInTeam": ss.Channel().SearchInTeam,
@@ -1986,6 +2015,19 @@ func testChannelStoreSearchInTeam(t *testing.T, ss store.Store) {
t.Fatal("wrong channel returned")
}
}
+
+ if result := <-search(o1.TeamId, "now searchable"); result.Err != nil {
+ t.Fatal(result.Err)
+ } else {
+ channels := result.Data.(*model.ChannelList)
+ if len(*channels) != 1 {
+ t.Fatal("should return 1 channel")
+ }
+
+ if (*channels)[0].Name != o12.Name {
+ t.Fatal("wrong channel returned")
+ }
+ }
})
}
}
diff --git a/store/storetest/mocks/LayeredStoreDatabaseLayer.go b/store/storetest/mocks/LayeredStoreDatabaseLayer.go
index adbe1068c..47b594a81 100644
--- a/store/storetest/mocks/LayeredStoreDatabaseLayer.go
+++ b/store/storetest/mocks/LayeredStoreDatabaseLayer.go
@@ -200,6 +200,11 @@ func (_m *LayeredStoreDatabaseLayer) License() store.LicenseStore {
return r0
}
+// LockToMaster provides a mock function with given fields:
+func (_m *LayeredStoreDatabaseLayer) LockToMaster() {
+ _m.Called()
+}
+
// MarkSystemRanUnitTests provides a mock function with given fields:
func (_m *LayeredStoreDatabaseLayer) MarkSystemRanUnitTests() {
_m.Called()
@@ -851,6 +856,11 @@ func (_m *LayeredStoreDatabaseLayer) TotalSearchDbConnections() int {
return r0
}
+// UnlockFromMaster provides a mock function with given fields:
+func (_m *LayeredStoreDatabaseLayer) UnlockFromMaster() {
+ _m.Called()
+}
+
// User provides a mock function with given fields:
func (_m *LayeredStoreDatabaseLayer) User() store.UserStore {
ret := _m.Called()
diff --git a/store/storetest/mocks/SqlStore.go b/store/storetest/mocks/SqlStore.go
index 021baa7d3..a0cc3f0cc 100644
--- a/store/storetest/mocks/SqlStore.go
+++ b/store/storetest/mocks/SqlStore.go
@@ -411,6 +411,11 @@ func (_m *SqlStore) License() store.LicenseStore {
return r0
}
+// LockToMaster provides a mock function with given fields:
+func (_m *SqlStore) LockToMaster() {
+ _m.Called()
+}
+
// MarkSystemRanUnitTests provides a mock function with given fields:
func (_m *SqlStore) MarkSystemRanUnitTests() {
_m.Called()
@@ -706,6 +711,11 @@ func (_m *SqlStore) TotalSearchDbConnections() int {
return r0
}
+// UnlockFromMaster provides a mock function with given fields:
+func (_m *SqlStore) UnlockFromMaster() {
+ _m.Called()
+}
+
// User provides a mock function with given fields:
func (_m *SqlStore) User() store.UserStore {
ret := _m.Called()
diff --git a/store/storetest/mocks/Store.go b/store/storetest/mocks/Store.go
index dd1967cd5..3a5b7726c 100644
--- a/store/storetest/mocks/Store.go
+++ b/store/storetest/mocks/Store.go
@@ -198,6 +198,11 @@ func (_m *Store) License() store.LicenseStore {
return r0
}
+// LockToMaster provides a mock function with given fields:
+func (_m *Store) LockToMaster() {
+ _m.Called()
+}
+
// MarkSystemRanUnitTests provides a mock function with given fields:
func (_m *Store) MarkSystemRanUnitTests() {
_m.Called()
@@ -437,6 +442,11 @@ func (_m *Store) TotalSearchDbConnections() int {
return r0
}
+// UnlockFromMaster provides a mock function with given fields:
+func (_m *Store) UnlockFromMaster() {
+ _m.Called()
+}
+
// User provides a mock function with given fields:
func (_m *Store) User() store.UserStore {
ret := _m.Called()
diff --git a/store/storetest/store.go b/store/storetest/store.go
index 677a63101..e73596ec4 100644
--- a/store/storetest/store.go
+++ b/store/storetest/store.go
@@ -77,6 +77,8 @@ func (s *Store) ChannelMemberHistory() store.ChannelMemberHistoryStore {
}
func (s *Store) MarkSystemRanUnitTests() { /* do nothing */ }
func (s *Store) Close() { /* do nothing */ }
+func (s *Store) LockToMaster() { /* do nothing */ }
+func (s *Store) UnlockFromMaster() { /* do nothing */ }
func (s *Store) DropAllTables() { /* do nothing */ }
func (s *Store) TotalMasterDbConnections() int { return 1 }
func (s *Store) TotalReadDbConnections() int { return 1 }