diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-05-01 17:40:04 -0400 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2017-05-01 17:40:04 -0400 |
commit | 935405f19d4a0d78f1a84964460635ec5a091e0c (patch) | |
tree | f08d4fed124e6154785ba092c4c96143d2b6abf5 /store/sql_user_store.go | |
parent | 2d22fb5652e547b4fe169dee2ea9cd14f747a485 (diff) | |
download | chat-935405f19d4a0d78f1a84964460635ec5a091e0c.tar.gz chat-935405f19d4a0d78f1a84964460635ec5a091e0c.tar.bz2 chat-935405f19d4a0d78f1a84964460635ec5a091e0c.zip |
Copy users in/out out profileByIds cache to prevent data race (#6179)
Diffstat (limited to 'store/sql_user_store.go')
-rw-r--r-- | store/sql_user_store.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/store/sql_user_store.go b/store/sql_user_store.go index 9d981b13e..d18da8df8 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -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 |