Merge branch 'master' into advanced-permissions-phase-1
Этот коммит содержится в:
@@ -43,12 +43,20 @@ var allChannelMembersNotifyPropsForChannelCache = utils.NewLru(ALL_CHANNEL_MEMBE
|
||||
var channelCache = utils.NewLru(model.CHANNEL_CACHE_SIZE)
|
||||
var channelByNameCache = utils.NewLru(model.CHANNEL_CACHE_SIZE)
|
||||
|
||||
func ClearChannelCaches() {
|
||||
func (s SqlChannelStore) ClearCaches() {
|
||||
channelMemberCountsCache.Purge()
|
||||
allChannelMembersForUserCache.Purge()
|
||||
allChannelMembersNotifyPropsForChannelCache.Purge()
|
||||
channelCache.Purge()
|
||||
channelByNameCache.Purge()
|
||||
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheInvalidationCounter("Channel Member Counts - Purge")
|
||||
s.metrics.IncrementMemCacheInvalidationCounter("All Channel Members for User - Purge")
|
||||
s.metrics.IncrementMemCacheInvalidationCounter("All Channel Members Notify Props for Channel - Purge")
|
||||
s.metrics.IncrementMemCacheInvalidationCounter("Channel - Purge")
|
||||
s.metrics.IncrementMemCacheInvalidationCounter("Channel By Name - Purge")
|
||||
}
|
||||
}
|
||||
|
||||
func NewSqlChannelStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) store.ChannelStore {
|
||||
@@ -308,12 +316,18 @@ func (s SqlChannelStore) GetChannelUnread(channelId, userId string) store.StoreC
|
||||
})
|
||||
}
|
||||
|
||||
func (us SqlChannelStore) InvalidateChannel(id string) {
|
||||
func (s SqlChannelStore) InvalidateChannel(id string) {
|
||||
channelCache.Remove(id)
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheInvalidationCounter("Channel - Remove by ChannelId")
|
||||
}
|
||||
}
|
||||
|
||||
func (us SqlChannelStore) InvalidateChannelByName(teamId, name string) {
|
||||
func (s SqlChannelStore) InvalidateChannelByName(teamId, name string) {
|
||||
channelByNameCache.Remove(teamId + name)
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheInvalidationCounter("Channel by Name - Remove by TeamId and Name")
|
||||
}
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) Get(id string, allowFromCache bool) store.StoreChannel {
|
||||
@@ -814,14 +828,17 @@ func (s SqlChannelStore) GetMember(channelId string, userId string) store.StoreC
|
||||
})
|
||||
}
|
||||
|
||||
func (us SqlChannelStore) InvalidateAllChannelMembersForUser(userId string) {
|
||||
func (s SqlChannelStore) InvalidateAllChannelMembersForUser(userId string) {
|
||||
allChannelMembersForUserCache.Remove(userId)
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheInvalidationCounter("All Channel Members for User - Remove by UserId")
|
||||
}
|
||||
}
|
||||
|
||||
func (us SqlChannelStore) IsUserInChannelUseCache(userId string, channelId string) bool {
|
||||
func (s SqlChannelStore) IsUserInChannelUseCache(userId string, channelId string) bool {
|
||||
if cacheItem, ok := allChannelMembersForUserCache.Get(userId); ok {
|
||||
if us.metrics != nil {
|
||||
us.metrics.IncrementMemCacheHitCounter("All Channel Members for User")
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheHitCounter("All Channel Members for User")
|
||||
}
|
||||
ids := cacheItem.(map[string]string)
|
||||
if _, ok := ids[channelId]; ok {
|
||||
@@ -830,12 +847,12 @@ func (us SqlChannelStore) IsUserInChannelUseCache(userId string, channelId strin
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
if us.metrics != nil {
|
||||
us.metrics.IncrementMemCacheMissCounter("All Channel Members for User")
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheMissCounter("All Channel Members for User")
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-us.GetAllChannelMembersForUser(userId, true); result.Err != nil {
|
||||
if result := <-s.GetAllChannelMembersForUser(userId, true); result.Err != nil {
|
||||
l4g.Error("SqlChannelStore.IsUserInChannelUseCache: " + result.Err.Error())
|
||||
return false
|
||||
} else {
|
||||
@@ -915,8 +932,11 @@ func (s SqlChannelStore) GetAllChannelMembersForUser(userId string, allowFromCac
|
||||
})
|
||||
}
|
||||
|
||||
func (us SqlChannelStore) InvalidateCacheForChannelMembersNotifyProps(channelId string) {
|
||||
func (s SqlChannelStore) InvalidateCacheForChannelMembersNotifyProps(channelId string) {
|
||||
allChannelMembersNotifyPropsForChannelCache.Remove(channelId)
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheInvalidationCounter("All Channel Members Notify Props for Channel - Remove by ChannelId")
|
||||
}
|
||||
}
|
||||
|
||||
type allChannelMemberNotifyProps struct {
|
||||
@@ -966,8 +986,11 @@ func (s SqlChannelStore) GetAllChannelMembersNotifyPropsForChannel(channelId str
|
||||
})
|
||||
}
|
||||
|
||||
func (us SqlChannelStore) InvalidateMemberCount(channelId string) {
|
||||
func (s SqlChannelStore) InvalidateMemberCount(channelId string) {
|
||||
channelMemberCountsCache.Remove(channelId)
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheInvalidationCounter("Channel Member Counts - Remove by ChannelId")
|
||||
}
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetMemberCountFromCache(channelId string) int64 {
|
||||
@@ -1225,19 +1248,6 @@ func (s SqlChannelStore) AnalyticsDeletedTypeCount(teamId string, channelType st
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) ExtraUpdateByUser(userId string, time int64) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
_, err := s.GetMaster().Exec(
|
||||
`UPDATE Channels SET ExtraUpdateAt = :Time
|
||||
WHERE Id IN (SELECT ChannelId FROM ChannelMembers WHERE UserId = :UserId);`,
|
||||
map[string]interface{}{"UserId": userId, "Time": time})
|
||||
|
||||
if err != nil {
|
||||
result.Err = model.NewAppError("SqlChannelStore.extraUpdated", "store.sql_channel.extra_updated.app_error", nil, "user_id="+userId+", "+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (s SqlChannelStore) GetMembersForUser(teamId string, userId string) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
members := &model.ChannelMembers{}
|
||||
|
||||
@@ -138,6 +138,7 @@ func (s SqlComplianceStore) ComplianceExport(job *model.Compliance) store.StoreC
|
||||
Teams.DisplayName AS TeamDisplayName,
|
||||
Channels.Name AS ChannelName,
|
||||
Channels.DisplayName AS ChannelDisplayName,
|
||||
Channels.Type AS ChannelType,
|
||||
Users.Username AS UserUsername,
|
||||
Users.Email AS UserEmail,
|
||||
Users.Nickname AS UserNickname,
|
||||
@@ -172,6 +173,7 @@ func (s SqlComplianceStore) ComplianceExport(job *model.Compliance) store.StoreC
|
||||
'Direct Messages' AS TeamDisplayName,
|
||||
Channels.Name AS ChannelName,
|
||||
Channels.DisplayName AS ChannelDisplayName,
|
||||
Channels.Type AS ChannelType,
|
||||
Users.Username AS UserUsername,
|
||||
Users.Email AS UserEmail,
|
||||
Users.Nickname AS UserNickname,
|
||||
@@ -223,7 +225,12 @@ func (s SqlComplianceStore) MessageExport(after int64, limit int) store.StoreCha
|
||||
Posts.Type AS PostType,
|
||||
Posts.FileIds AS PostFileIds,
|
||||
Channels.Id AS ChannelId,
|
||||
Channels.DisplayName AS ChannelDisplayName,
|
||||
CASE
|
||||
WHEN Channels.Type = 'D' THEN 'Direct Message'
|
||||
WHEN Channels.Type = 'G' THEN 'Group Message'
|
||||
ELSE Channels.DisplayName
|
||||
END AS ChannelDisplayName,
|
||||
Channels.Type AS ChannelType,
|
||||
Users.Id AS UserId,
|
||||
Users.Email AS UserEmail,
|
||||
Users.Username
|
||||
|
||||
@@ -25,8 +25,11 @@ const (
|
||||
|
||||
var fileInfoCache *utils.Cache = utils.NewLru(FILE_INFO_CACHE_SIZE)
|
||||
|
||||
func ClearFileCaches() {
|
||||
func (fs SqlFileInfoStore) ClearCaches() {
|
||||
fileInfoCache.Purge()
|
||||
if fs.metrics != nil {
|
||||
fs.metrics.IncrementMemCacheInvalidationCounter("File Info Cache - Purge")
|
||||
}
|
||||
}
|
||||
|
||||
func NewSqlFileInfoStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) store.FileInfoStore {
|
||||
@@ -118,6 +121,9 @@ func (fs SqlFileInfoStore) GetByPath(path string) store.StoreChannel {
|
||||
|
||||
func (fs SqlFileInfoStore) InvalidateFileInfosForPostCache(postId string) {
|
||||
fileInfoCache.Remove(postId)
|
||||
if fs.metrics != nil {
|
||||
fs.metrics.IncrementMemCacheInvalidationCounter("File Info Cache - Remove by PostId")
|
||||
}
|
||||
}
|
||||
|
||||
func (fs SqlFileInfoStore) GetForPost(postId string, readFromMaster bool, allowFromCache bool) store.StoreChannel {
|
||||
|
||||
@@ -35,9 +35,14 @@ const (
|
||||
var lastPostTimeCache = utils.NewLru(LAST_POST_TIME_CACHE_SIZE)
|
||||
var lastPostsCache = utils.NewLru(LAST_POSTS_CACHE_SIZE)
|
||||
|
||||
func ClearPostCaches() {
|
||||
func (s SqlPostStore) ClearCaches() {
|
||||
lastPostTimeCache.Purge()
|
||||
lastPostsCache.Purge()
|
||||
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheInvalidationCounter("Last Post Time - Purge")
|
||||
s.metrics.IncrementMemCacheInvalidationCounter("Last Posts Cache - Purge")
|
||||
}
|
||||
}
|
||||
|
||||
func NewSqlPostStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) store.PostStore {
|
||||
@@ -326,6 +331,11 @@ func (s SqlPostStore) InvalidateLastPostTimeCache(channelId string) {
|
||||
// Keys are "{channelid}{limit}" and caching only occurs on limits of 30 and 60
|
||||
lastPostsCache.Remove(channelId + "30")
|
||||
lastPostsCache.Remove(channelId + "60")
|
||||
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheInvalidationCounter("Last Post Time - Remove by Channel Id")
|
||||
s.metrics.IncrementMemCacheInvalidationCounter("Last Posts Cache - Remove by Channel Id")
|
||||
}
|
||||
}
|
||||
|
||||
func (s SqlPostStore) GetEtag(channelId string, allowFromCache bool) store.StoreChannel {
|
||||
|
||||
@@ -15,6 +15,7 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
VERSION_4_9_0 = "4.9.0"
|
||||
VERSION_4_8_0 = "4.8.0"
|
||||
VERSION_4_7_1 = "4.7.1"
|
||||
VERSION_4_7_0 = "4.7.0"
|
||||
@@ -68,6 +69,7 @@ func UpgradeDatabase(sqlStore SqlStore) {
|
||||
UpgradeDatabaseToVersion47(sqlStore)
|
||||
UpgradeDatabaseToVersion471(sqlStore)
|
||||
UpgradeDatabaseToVersion48(sqlStore)
|
||||
UpgradeDatabaseToVersion49(sqlStore)
|
||||
|
||||
// If the SchemaVersion is empty this this is the first time it has ran
|
||||
// so lets set it to the current version.
|
||||
@@ -365,13 +367,19 @@ func UpgradeDatabaseToVersion471(sqlStore SqlStore) {
|
||||
}
|
||||
|
||||
func UpgradeDatabaseToVersion48(sqlStore SqlStore) {
|
||||
if shouldPerformUpgrade(sqlStore, VERSION_4_7_1, VERSION_4_8_0) {
|
||||
saveSchemaVersion(sqlStore, VERSION_4_8_0)
|
||||
}
|
||||
}
|
||||
|
||||
func UpgradeDatabaseToVersion49(sqlStore SqlStore) {
|
||||
// This version of Mattermost includes an App-Layer migration which migrates from hard-coded roles configured by
|
||||
// a number of parameters in `config.json` to a `Roles` table in the database. The migration code can be seen
|
||||
// in the file `app/app.go` in the function `DoAdvancedPermissionsMigration()`.
|
||||
|
||||
//TODO: Uncomment the following condition when version 4.8.0 is released
|
||||
//if shouldPerformUpgrade(sqlStore, VERSION_4_7_0, VERSION_4_8_0) {
|
||||
//TODO: Uncomment the following condition when version 4.9.0 is released
|
||||
//if shouldPerformUpgrade(sqlStore, VERSION_4_8_0, VERSION_4_9_0) {
|
||||
sqlStore.CreateColumnIfNotExists("Teams", "LastTeamIconUpdate", "bigint", "bigint", "0")
|
||||
// saveSchemaVersion(sqlStore, VERSION_4_8_0)
|
||||
// saveSchemaVersion(sqlStore, VERSION_4_9_0)
|
||||
//}
|
||||
}
|
||||
|
||||
@@ -38,13 +38,22 @@ type SqlUserStore struct {
|
||||
var profilesInChannelCache *utils.Cache = utils.NewLru(PROFILES_IN_CHANNEL_CACHE_SIZE)
|
||||
var profileByIdsCache *utils.Cache = utils.NewLru(PROFILE_BY_IDS_CACHE_SIZE)
|
||||
|
||||
func ClearUserCaches() {
|
||||
func (us SqlUserStore) ClearCaches() {
|
||||
profilesInChannelCache.Purge()
|
||||
profileByIdsCache.Purge()
|
||||
|
||||
if us.metrics != nil {
|
||||
us.metrics.IncrementMemCacheInvalidationCounter("Profiles in Channel - Purge")
|
||||
us.metrics.IncrementMemCacheInvalidationCounter("Profile By Ids - Purge")
|
||||
}
|
||||
}
|
||||
|
||||
func (us SqlUserStore) InvalidatProfileCacheForUser(userId string) {
|
||||
profileByIdsCache.Remove(userId)
|
||||
|
||||
if us.metrics != nil {
|
||||
us.metrics.IncrementMemCacheInvalidationCounter("Profile By Ids - Remove")
|
||||
}
|
||||
}
|
||||
|
||||
func NewSqlUserStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) store.UserStore {
|
||||
@@ -384,6 +393,9 @@ func (us SqlUserStore) InvalidateProfilesInChannelCacheByUser(userId string) {
|
||||
userMap := cacheItem.(map[string]*model.User)
|
||||
if _, userInCache := userMap[userId]; userInCache {
|
||||
profilesInChannelCache.Remove(key)
|
||||
if us.metrics != nil {
|
||||
us.metrics.IncrementMemCacheInvalidationCounter("Profiles in Channel - Remove by User")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -391,13 +403,27 @@ func (us SqlUserStore) InvalidateProfilesInChannelCacheByUser(userId string) {
|
||||
|
||||
func (us SqlUserStore) InvalidateProfilesInChannelCache(channelId string) {
|
||||
profilesInChannelCache.Remove(channelId)
|
||||
if us.metrics != nil {
|
||||
us.metrics.IncrementMemCacheInvalidationCounter("Profiles in Channel - Remove by Channel")
|
||||
}
|
||||
}
|
||||
|
||||
func (us SqlUserStore) GetProfilesInChannel(channelId string, offset int, limit int) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
var users []*model.User
|
||||
|
||||
query := "SELECT Users.* FROM Users, ChannelMembers WHERE ChannelMembers.ChannelId = :ChannelId AND Users.Id = ChannelMembers.UserId ORDER BY Users.Username ASC LIMIT :Limit OFFSET :Offset"
|
||||
query := `
|
||||
SELECT
|
||||
Users.*
|
||||
FROM
|
||||
Users, ChannelMembers
|
||||
WHERE
|
||||
ChannelMembers.ChannelId = :ChannelId
|
||||
AND Users.Id = ChannelMembers.UserId
|
||||
ORDER BY
|
||||
Users.Username ASC
|
||||
LIMIT :Limit OFFSET :Offset
|
||||
`
|
||||
|
||||
if _, err := us.GetReplica().Select(&users, query, map[string]interface{}{"ChannelId": channelId, "Offset": offset, "Limit": limit}); err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.GetProfilesInChannel", "store.sql_user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
@@ -412,6 +438,42 @@ func (us SqlUserStore) GetProfilesInChannel(channelId string, offset int, limit
|
||||
})
|
||||
}
|
||||
|
||||
func (us SqlUserStore) GetProfilesInChannelByStatus(channelId string, offset int, limit int) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
var users []*model.User
|
||||
|
||||
query := `
|
||||
SELECT
|
||||
Users.*
|
||||
FROM Users
|
||||
INNER JOIN ChannelMembers ON Users.Id = ChannelMembers.UserId
|
||||
LEFT JOIN Status ON Users.Id = Status.UserId
|
||||
WHERE
|
||||
ChannelMembers.ChannelId = :ChannelId
|
||||
ORDER BY
|
||||
CASE Status
|
||||
WHEN 'online' THEN 1
|
||||
WHEN 'away' THEN 2
|
||||
WHEN 'dnd' THEN 3
|
||||
ELSE 4
|
||||
END,
|
||||
Users.Username ASC
|
||||
LIMIT :Limit OFFSET :Offset
|
||||
`
|
||||
|
||||
if _, err := us.GetReplica().Select(&users, query, map[string]interface{}{"ChannelId": channelId, "Offset": offset, "Limit": limit}); err != nil {
|
||||
result.Err = model.NewAppError("SqlUserStore.GetProfilesInChannelByStatus", "store.sql_user.get_profiles.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||
} else {
|
||||
|
||||
for _, u := range users {
|
||||
u.Sanitize(map[string]bool{})
|
||||
}
|
||||
|
||||
result.Data = users
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func (us SqlUserStore) GetAllProfilesInChannel(channelId string, allowFromCache bool) store.StoreChannel {
|
||||
return store.Do(func(result *store.StoreResult) {
|
||||
if allowFromCache {
|
||||
|
||||
@@ -26,8 +26,12 @@ const (
|
||||
|
||||
var webhookCache = utils.NewLru(WEBHOOK_CACHE_SIZE)
|
||||
|
||||
func ClearWebhookCaches() {
|
||||
func (s SqlWebhookStore) ClearCaches() {
|
||||
webhookCache.Purge()
|
||||
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheInvalidationCounter("Webhook - Purge")
|
||||
}
|
||||
}
|
||||
|
||||
func NewSqlWebhookStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) store.WebhookStore {
|
||||
@@ -78,6 +82,9 @@ func (s SqlWebhookStore) CreateIndexesIfNotExists() {
|
||||
|
||||
func (s SqlWebhookStore) InvalidateWebhookCache(webhookId string) {
|
||||
webhookCache.Remove(webhookId)
|
||||
if s.metrics != nil {
|
||||
s.metrics.IncrementMemCacheInvalidationCounter("Webhook - Remove by WebhookId")
|
||||
}
|
||||
}
|
||||
|
||||
func (s SqlWebhookStore) SaveIncoming(webhook *model.IncomingWebhook) store.StoreChannel {
|
||||
@@ -164,7 +171,7 @@ func (s SqlWebhookStore) PermanentDeleteIncomingByUser(userId string) store.Stor
|
||||
result.Err = model.NewAppError("SqlWebhookStore.DeleteIncomingByUser", "store.sql_webhooks.permanent_delete_incoming_by_user.app_error", nil, "id="+userId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
ClearWebhookCaches()
|
||||
s.ClearCaches()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -175,7 +182,7 @@ func (s SqlWebhookStore) PermanentDeleteIncomingByChannel(channelId string) stor
|
||||
result.Err = model.NewAppError("SqlWebhookStore.DeleteIncomingByChannel", "store.sql_webhooks.permanent_delete_incoming_by_channel.app_error", nil, "id="+channelId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
ClearWebhookCaches()
|
||||
s.ClearCaches()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -322,7 +329,7 @@ func (s SqlWebhookStore) PermanentDeleteOutgoingByChannel(channelId string) stor
|
||||
result.Err = model.NewAppError("SqlWebhookStore.DeleteOutgoingByChannel", "store.sql_webhooks.permanent_delete_outgoing_by_channel.app_error", nil, "id="+channelId+", err="+err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
ClearWebhookCaches()
|
||||
s.ClearCaches()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user