Skip to content

Commit

Permalink
fix: avoid the same pointers to different users
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyXiang committed Mar 13, 2022
1 parent 75eee6a commit a3fae8e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions handler/plex.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ func (c *PlexClient) fetchUsers(token string) {
c.MulLock.Lock(lockKeyUsers)
defer c.MulLock.Unlock(lockKeyUsers)

var user plexUser
ctx := context.Background()
cacheKey := fmt.Sprintf("%s:token:%s", cachePrefixPlex, token)
isCacheEnabled := redisClient != nil

if isCacheEnabled {
var user plexUser
err := redisClient.Get(ctx, cacheKey).Scan(&user)
if err == nil {
c.users[token] = &user
Expand All @@ -185,7 +185,7 @@ func (c *PlexClient) fetchUsers(token string) {

userInfo := c.GetAccountInfo(token)
if userInfo.ID > 0 {
user = plexUser{
user := plexUser{
Id: userInfo.ID,
Username: userInfo.Username,
}
Expand All @@ -199,7 +199,7 @@ func (c *PlexClient) fetchUsers(token string) {
response := c.GetSharedServers()
if response != nil {
for _, friend := range response.Friends {
user = plexUser{
user := plexUser{
Id: friend.UserId,
Username: friend.Username,
}
Expand Down

0 comments on commit a3fae8e

Please sign in to comment.