mirror of
https://github.com/diamondburned/arikawa.git
synced 2024-11-30 18:53:30 +00:00
Fixed a potential race condition in the default state storage
This commit is contained in:
parent
aa4154e73c
commit
2cd9def778
|
@ -16,6 +16,11 @@ type Store interface {
|
|||
// All methods in StoreGetter will be wrapped by the State. If the State can't
|
||||
// find anything in the storage, it will call the API itself and automatically
|
||||
// add what's missing into the storage.
|
||||
//
|
||||
// Methods that return with a slice should pay attention to race conditions that
|
||||
// would mutate the underlying slice (and as a result the returned slice as
|
||||
// well). The best way to avoid this is to copy the whole slice, like
|
||||
// DefaultStore does.
|
||||
type StoreGetter interface {
|
||||
Self() (*discord.User, error)
|
||||
|
||||
|
|
|
@ -114,7 +114,7 @@ func (s *DefaultStore) Channels(
|
|||
return nil, ErrStoreNotFound
|
||||
}
|
||||
|
||||
return chs, nil
|
||||
return append([]discord.Channel{}, chs...), nil
|
||||
}
|
||||
|
||||
func (s *DefaultStore) PrivateChannels() ([]discord.Channel, error) {
|
||||
|
@ -221,7 +221,7 @@ func (s *DefaultStore) Emojis(
|
|||
return nil, ErrStoreNotFound
|
||||
}
|
||||
|
||||
return gd.Emojis, nil
|
||||
return append([]discord.Emoji{}, gd.Emojis...), nil
|
||||
}
|
||||
|
||||
func (s *DefaultStore) EmojiSet(
|
||||
|
@ -353,7 +353,7 @@ func (s *DefaultStore) Members(
|
|||
return nil, ErrStoreNotFound
|
||||
}
|
||||
|
||||
return ms, nil
|
||||
return append([]discord.Member{}, ms...), nil
|
||||
}
|
||||
|
||||
func (s *DefaultStore) MemberSet(
|
||||
|
@ -437,7 +437,7 @@ func (s *DefaultStore) Messages(
|
|||
return nil, ErrStoreNotFound
|
||||
}
|
||||
|
||||
return ms, nil
|
||||
return append([]discord.Message{}, ms...), nil
|
||||
}
|
||||
|
||||
func (s *DefaultStore) MaxMessages() int {
|
||||
|
@ -561,7 +561,7 @@ func (s *DefaultStore) Presences(
|
|||
return nil, ErrStoreNotFound
|
||||
}
|
||||
|
||||
return ps, nil
|
||||
return append([]discord.Presence{}, ps...), nil
|
||||
}
|
||||
|
||||
func (s *DefaultStore) PresenceSet(
|
||||
|
@ -640,7 +640,7 @@ func (s *DefaultStore) Roles(
|
|||
return nil, ErrStoreNotFound
|
||||
}
|
||||
|
||||
return gd.Roles, nil
|
||||
return append([]discord.Role{}, gd.Roles...), nil
|
||||
}
|
||||
|
||||
func (s *DefaultStore) RoleSet(
|
||||
|
|
Loading…
Reference in a new issue