Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
patch a potential nil issue in guild create
Browse files Browse the repository at this point in the history
  • Loading branch information
andersfylling committed Feb 17, 2021
1 parent 780b4a6 commit 8a1aa88
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,13 @@ func (c *CacheLFUImmutable) GuildMembersChunk(data []byte) (evt *GuildMembersChu
if evt, err = c.CacheNop.GuildMembersChunk(data); err != nil {
return nil, err
}

users := make([]*User, 0, len(evt.Members))
for i := range evt.Members {
users = append(users, evt.Members[i].User)
evt.Members[i].User = nil
}

wg := &sync.WaitGroup{}
wg.Add(1)
go func() {
Expand All @@ -348,6 +348,7 @@ func (c *CacheLFUImmutable) GuildMembersChunk(data []byte) (evt *GuildMembersChu
if !exists || cachedGuild == nil {
cachedGuild = c.Guilds.CreateCacheableItem(&Guild{
ID: evt.GuildID,
Unavailable: true,
})
c.Guilds.Set(evt.GuildID, cachedGuild)
}
Expand All @@ -371,9 +372,8 @@ func (c *CacheLFUImmutable) GuildMembersChunk(data []byte) (evt *GuildMembersChu
}
members = append(members, evt.Members...)
guild.Members = members

mutex.Unlock()

mutex.Unlock()

wg.Wait()
return c.CacheNop.GuildMembersChunk(data)
Expand Down Expand Up @@ -563,14 +563,7 @@ func (c *CacheLFUImmutable) GuildCreate(data []byte) (*GuildCreate, error) {
c.Patch(guild)

guild = DeepCopy(guild).(*Guild)
} else if exists {
// not pre-loaded from ready event
// data should somehow already exist, duplicate create event maybe?
if err := json.Unmarshal(data, guild); err != nil {
return nil, err
}
c.Patch(guild)
} else {
} else if !exists {
// must create it
if err := json.Unmarshal(data, &guild); err != nil {
return nil, err
Expand All @@ -583,8 +576,15 @@ func (c *CacheLFUImmutable) GuildCreate(data []byte) (*GuildCreate, error) {
c.Guilds.Lock()
if _, exists := c.Guilds.Get(guildID); !exists {
c.Guilds.Set(guildID, e)
} // TODO: unmarshal if unavailable
}
c.Guilds.Unlock()
} else {
// derp - this is really.. not supposed to happen but just in case
evt, err := c.CacheNop.GuildCreate(data)
if err != nil {
return nil, err
}
guild = evt.Guild
}

// cache channels
Expand Down

0 comments on commit 8a1aa88

Please sign in to comment.