Migrate profileByIdsCache cache to cache layer (#13133)
* Partial advances * Small advances * invalidating cache with doInvalidateCacheCluster * Renamed cache * Starting with tests (failing by now) * Passing tests :) * Passing tests * Fix ineffectual assignment in tests * Revert of backward incompatible change * Removed unused var
Этот коммит содержится в:
коммит произвёл
Jesús Espino
родитель
22b495b2df
Коммит
27375cd081
@@ -23,8 +23,6 @@ import (
|
||||
const (
|
||||
PROFILES_IN_CHANNEL_CACHE_SIZE = model.CHANNEL_CACHE_SIZE
|
||||
PROFILES_IN_CHANNEL_CACHE_SEC = 900 // 15 mins
|
||||
PROFILE_BY_IDS_CACHE_SIZE = model.SESSION_CACHE_SIZE
|
||||
PROFILE_BY_IDS_CACHE_SEC = 900 // 15 mins
|
||||
MAX_GROUP_CHANNELS_FOR_PROFILES = 50
|
||||
)
|
||||
|
||||
@@ -44,25 +42,16 @@ 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 (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 (us SqlUserStore) InvalidatProfileCacheForUser(userId string) {}
|
||||
|
||||
func NewSqlUserStore(sqlStore SqlStore, metrics einterfaces.MetricsInterface) store.UserStore {
|
||||
us := &SqlUserStore{
|
||||
@@ -829,46 +818,15 @@ func (us SqlUserStore) GetNewUsersForTeam(teamId string, offset, limit int, view
|
||||
return users, nil
|
||||
}
|
||||
|
||||
func (us SqlUserStore) GetProfileByIds(userIds []string, options *store.UserGetByIdsOpts, allowFromCache bool) ([]*model.User, *model.AppError) {
|
||||
func (us SqlUserStore) GetProfileByIds(userIds []string, options *store.UserGetByIdsOpts, _ bool) ([]*model.User, *model.AppError) {
|
||||
if options == nil {
|
||||
options = &store.UserGetByIdsOpts{}
|
||||
}
|
||||
|
||||
users := []*model.User{}
|
||||
remainingUserIds := make([]string, 0)
|
||||
|
||||
if allowFromCache {
|
||||
for _, userId := range userIds {
|
||||
if cacheItem, ok := profileByIdsCache.Get(userId); ok {
|
||||
u := &model.User{}
|
||||
*u = *cacheItem.(*model.User)
|
||||
|
||||
if options.Since == 0 || u.UpdateAt > options.Since {
|
||||
users = append(users, u)
|
||||
}
|
||||
} else {
|
||||
remainingUserIds = append(remainingUserIds, userId)
|
||||
}
|
||||
}
|
||||
if us.metrics != nil {
|
||||
us.metrics.AddMemCacheHitCounter("Profile By Ids", float64(len(users)))
|
||||
us.metrics.AddMemCacheMissCounter("Profile By Ids", float64(len(remainingUserIds)))
|
||||
}
|
||||
} else {
|
||||
remainingUserIds = userIds
|
||||
if us.metrics != nil {
|
||||
us.metrics.AddMemCacheMissCounter("Profile By Ids", float64(len(remainingUserIds)))
|
||||
}
|
||||
}
|
||||
|
||||
// If everything came from the cache then just return
|
||||
if len(remainingUserIds) == 0 {
|
||||
return users, nil
|
||||
}
|
||||
|
||||
query := us.usersQuery.
|
||||
Where(map[string]interface{}{
|
||||
"u.Id": remainingUserIds,
|
||||
"u.Id": userIds,
|
||||
}).
|
||||
OrderBy("u.Username ASC")
|
||||
|
||||
@@ -891,10 +849,6 @@ func (us SqlUserStore) GetProfileByIds(userIds []string, options *store.UserGetB
|
||||
|
||||
for _, u := range users {
|
||||
u.Sanitize(map[string]bool{})
|
||||
|
||||
cpy := &model.User{}
|
||||
*cpy = *u
|
||||
profileByIdsCache.AddWithExpiresInSecs(cpy.Id, cpy, PROFILE_BY_IDS_CACHE_SEC)
|
||||
}
|
||||
|
||||
return users, nil
|
||||
|
||||
Ссылка в новой задаче
Block a user