diff options
author | bodqhrohro <bodqhrohro@gmail.com> | 2019-12-28 05:35:40 +0300 |
---|---|---|
committer | bodqhrohro <bodqhrohro@gmail.com> | 2019-12-28 05:35:40 +0300 |
commit | 536451f648bce43aa34e90a9154adf831027dae7 (patch) | |
tree | 36c66093319e3972f97a141c68e332e25d468331 /telegram/utils.go | |
parent | fdc8397b93ed355cb931646f0c4eda496ce0e858 (diff) |
Make the chats/users cache thread-safe
Diffstat (limited to 'telegram/utils.go')
-rw-r--r-- | telegram/utils.go | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/telegram/utils.go b/telegram/utils.go index cef5167..0a0a3fc 100644 --- a/telegram/utils.go +++ b/telegram/utils.go @@ -58,7 +58,7 @@ func (c *Client) GetContactByID(id int64, chat *client.Chat) (*client.Chat, *cli if id <= math.MaxInt32 && id >= math.MinInt32 { userID := int32(id) - user, ok = c.cache.users[userID] + user, ok = c.cache.GetUser(userID) if !ok && userID > 0 { user, err = c.client.GetUser(&client.GetUserRequest{ UserId: userID, @@ -67,11 +67,11 @@ func (c *Client) GetContactByID(id int64, chat *client.Chat) (*client.Chat, *cli return nil, nil, err } - c.cache.users[userID] = user + c.cache.SetUser(userID, user) } } - cacheChat, ok = c.cache.chats[id] + cacheChat, ok = c.cache.GetChat(id) if !ok { if chat == nil { cacheChat, err = c.client.GetChat(&client.GetChatRequest{ @@ -86,9 +86,9 @@ func (c *Client) GetContactByID(id int64, chat *client.Chat) (*client.Chat, *cli return nil, nil, err } - c.cache.chats[id] = cacheChat + c.cache.SetChat(id, cacheChat) } else { - c.cache.chats[id] = chat + c.cache.SetChat(id, chat) } } if chat == nil { |