summaryrefslogtreecommitdiffstats
path: root/store
diff options
context:
space:
mode:
Diffstat (limited to 'store')
-rw-r--r--store/sql_channel_store.go26
-rw-r--r--store/sql_status_store.go2
-rw-r--r--store/sql_upgrade.go38
-rw-r--r--store/sql_user_store.go20
-rw-r--r--store/store.go2
5 files changed, 63 insertions, 25 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go
index 5107a0bd8..aadeed7c3 100644
--- a/store/sql_channel_store.go
+++ b/store/sql_channel_store.go
@@ -464,6 +464,32 @@ func (s SqlChannelStore) GetChannelCounts(teamId string, userId string) StoreCha
return storeChannel
}
+func (s SqlChannelStore) GetTeamChannels(teamId string) StoreChannel {
+ storeChannel := make(StoreChannel, 1)
+
+ go func() {
+ result := StoreResult{}
+
+ data := &model.ChannelList{}
+ _, err := s.GetReplica().Select(data, "SELECT * FROM Channels WHERE TeamId = :TeamId And Type != 'D' ORDER BY DisplayName", map[string]interface{}{"TeamId": teamId})
+
+ if err != nil {
+ result.Err = model.NewLocAppError("SqlChannelStore.GetChannels", "store.sql_channel.get_channels.get.app_error", nil, "teamId="+teamId+", err="+err.Error())
+ } else {
+ if len(*data) == 0 {
+ result.Err = model.NewLocAppError("SqlChannelStore.GetChannels", "store.sql_channel.get_channels.not_found.app_error", nil, "teamId="+teamId)
+ } else {
+ result.Data = data
+ }
+ }
+
+ storeChannel <- result
+ close(storeChannel)
+ }()
+
+ return storeChannel
+}
+
func (s SqlChannelStore) GetByName(teamId string, name string) StoreChannel {
storeChannel := make(StoreChannel, 1)
diff --git a/store/sql_status_store.go b/store/sql_status_store.go
index 7b9fdea5d..49a38a5c9 100644
--- a/store/sql_status_store.go
+++ b/store/sql_status_store.go
@@ -190,7 +190,7 @@ func (s SqlStatusStore) ResetAll() StoreChannel {
go func() {
result := StoreResult{}
- if _, err := s.GetMaster().Exec("UPDATE Status SET Status = :Status WHERE Manual = 0", map[string]interface{}{"Status": model.STATUS_OFFLINE}); err != nil {
+ if _, err := s.GetMaster().Exec("UPDATE Status SET Status = :Status WHERE Manual = false", map[string]interface{}{"Status": model.STATUS_OFFLINE}); err != nil {
result.Err = model.NewLocAppError("SqlStatusStore.ResetAll", "store.sql_status.reset_all.app_error", nil, "")
}
diff --git a/store/sql_upgrade.go b/store/sql_upgrade.go
index 824d0c3f0..992fac189 100644
--- a/store/sql_upgrade.go
+++ b/store/sql_upgrade.go
@@ -189,28 +189,24 @@ func UpgradeDatabaseToVersion34(sqlStore *SqlStore) {
}
func UpgradeDatabaseToVersion35(sqlStore *SqlStore) {
- //if shouldPerformUpgrade(sqlStore, VERSION_3_4_0, VERSION_3_5_0) {
-
- sqlStore.GetMaster().Exec("UPDATE Users SET Roles = 'system_user' WHERE Roles = ''")
- sqlStore.GetMaster().Exec("UPDATE Users SET Roles = 'system_user system_admin' WHERE Roles = 'system_admin'")
- sqlStore.GetMaster().Exec("UPDATE TeamMembers SET Roles = 'team_user' WHERE Roles = ''")
- sqlStore.GetMaster().Exec("UPDATE TeamMembers SET Roles = 'team_user team_admin' WHERE Roles = 'admin'")
- sqlStore.GetMaster().Exec("UPDATE ChannelMembers SET Roles = 'channel_user' WHERE Roles = ''")
- sqlStore.GetMaster().Exec("UPDATE ChannelMembers SET Roles = 'channel_user channel_admin' WHERE Roles = 'admin'")
+ if shouldPerformUpgrade(sqlStore, VERSION_3_4_0, VERSION_3_5_0) {
+ sqlStore.GetMaster().Exec("UPDATE Users SET Roles = 'system_user' WHERE Roles = ''")
+ sqlStore.GetMaster().Exec("UPDATE Users SET Roles = 'system_user system_admin' WHERE Roles = 'system_admin'")
+ sqlStore.GetMaster().Exec("UPDATE TeamMembers SET Roles = 'team_user' WHERE Roles = ''")
+ sqlStore.GetMaster().Exec("UPDATE TeamMembers SET Roles = 'team_user team_admin' WHERE Roles = 'admin'")
+ sqlStore.GetMaster().Exec("UPDATE ChannelMembers SET Roles = 'channel_user' WHERE Roles = ''")
+ sqlStore.GetMaster().Exec("UPDATE ChannelMembers SET Roles = 'channel_user channel_admin' WHERE Roles = 'admin'")
+
+ // The rest of the migration from Filenames -> FileIds is done lazily in api.GetFileInfosForPost
+ sqlStore.CreateColumnIfNotExists("Posts", "FileIds", "varchar(150)", "varchar(150)", "[]")
+
+ // Increase maximum length of the Channel table Purpose column.
+ if sqlStore.GetMaxLengthOfColumnIfExists("Channels", "Purpose") != "250" {
+ sqlStore.AlterColumnTypeIfExists("Channels", "Purpose", "varchar(250)", "varchar(250)")
+ }
- // The rest of the migration from Filenames -> FileIds is done lazily in api.GetFileInfosForPost
- sqlStore.CreateColumnIfNotExists("Posts", "FileIds", "varchar(150)", "varchar(150)", "[]")
+ sqlStore.Session().RemoveAllSessions()
- // Increase maximum length of the Channel table Purpose column.
- if sqlStore.GetMaxLengthOfColumnIfExists("Channels", "Purpose") != "250" {
- sqlStore.AlterColumnTypeIfExists("Channels", "Purpose", "varchar(250)", "varchar(250)")
+ saveSchemaVersion(sqlStore, VERSION_3_5_0)
}
-
- // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- // UNCOMMENT WHEN WE DO RELEASE
- // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- //sqlStore.Session().RemoveAllSessions()
-
- //saveSchemaVersion(sqlStore, VERSION_3_5_0)
- //}
}
diff --git a/store/sql_user_store.go b/store/sql_user_store.go
index 836a502fc..aa3bb4380 100644
--- a/store/sql_user_store.go
+++ b/store/sql_user_store.go
@@ -555,6 +555,19 @@ func (us SqlUserStore) GetProfiles(teamId string, offset int, limit int) StoreCh
return storeChannel
}
+func (us SqlUserStore) InvalidateProfilesInChannelCacheByUser(userId string) {
+ keys := profilesInChannelCache.Keys()
+
+ for _, key := range keys {
+ if cacheItem, ok := profilesInChannelCache.Get(key); ok {
+ userMap := cacheItem.(map[string]*model.User)
+ if _, userInCache := userMap[userId]; userInCache {
+ profilesInChannelCache.Remove(key)
+ }
+ }
+ }
+}
+
func (us SqlUserStore) InvalidateProfilesInChannelCache(channelId string) {
profilesInChannelCache.Remove(channelId)
}
@@ -1029,10 +1042,11 @@ func (us SqlUserStore) AnalyticsUniqueUserCount(teamId string) StoreChannel {
go func() {
result := StoreResult{}
- query := "SELECT COUNT(DISTINCT Email) FROM Users"
-
+ query := ""
if len(teamId) > 0 {
- query += ", TeamMembers WHERE TeamMembers.TeamId = :TeamId AND Users.Id = TeamMembers.UserId"
+ query = "SELECT COUNT(DISTINCT Users.Email) From Users, TeamMembers WHERE TeamMembers.TeamId = :TeamId AND Users.Id = TeamMembers.UserId AND TeamMembers.DeleteAt = 0 AND Users.DeleteAt = 0"
+ } else {
+ query = "SELECT COUNT(DISTINCT Email) FROM Users WHERE DeleteAt = 0"
}
v, err := us.GetReplica().SelectInt(query, map[string]interface{}{"TeamId": teamId})
diff --git a/store/store.go b/store/store.go
index b3d87da38..d0790263a 100644
--- a/store/store.go
+++ b/store/store.go
@@ -92,6 +92,7 @@ type ChannelStore interface {
GetChannels(teamId string, userId string) StoreChannel
GetMoreChannels(teamId string, userId string) StoreChannel
GetChannelCounts(teamId string, userId string) StoreChannel
+ GetTeamChannels(teamId string) StoreChannel
GetAll(teamId string) StoreChannel
GetForPost(postId string) StoreChannel
SaveMember(member *model.ChannelMember) StoreChannel
@@ -142,6 +143,7 @@ type UserStore interface {
UpdateMfaActive(userId string, active bool) StoreChannel
Get(id string) StoreChannel
GetAll() StoreChannel
+ InvalidateProfilesInChannelCacheByUser(userId string)
InvalidateProfilesInChannelCache(channelId string)
GetProfilesInChannel(channelId string, offset int, limit int, allowFromCache bool) StoreChannel
GetProfilesNotInChannel(teamId string, channelId string, offset int, limit int) StoreChannel