Copy users in/out out profileByIds cache to prevent data race (#6179)

Этот коммит содержится в:
Joram Wilander
2017-05-01 17:40:04 -04:00
коммит произвёл Harrison Healey
родитель 2d22fb5652
Коммит 935405f19d

Просмотреть файл

@@ -814,7 +814,8 @@ func (us SqlUserStore) GetProfileByIds(userIds []string, allowFromCache bool) St
if allowFromCache {
for _, userId := range userIds {
if cacheItem, ok := profileByIdsCache.Get(userId); ok {
u := cacheItem.(*model.User)
u := &model.User{}
*u = *cacheItem.(*model.User)
users = append(users, u)
} else {
remainingUserIds = append(remainingUserIds, userId)
@@ -855,7 +856,9 @@ func (us SqlUserStore) GetProfileByIds(userIds []string, allowFromCache bool) St
for _, u := range users {
u.Sanitize(map[string]bool{})
profileByIdsCache.AddWithExpiresInSecs(u.Id, u, PROFILE_BY_IDS_CACHE_SEC)
cpy := &model.User{}
*cpy = *u
profileByIdsCache.AddWithExpiresInSecs(cpy.Id, cpy, PROFILE_BY_IDS_CACHE_SEC)
}
result.Data = users