MM-60171: Using a generic function to allocate values (#28245)

We sprinkle a bit of generic magic to refactor a lot
of duplicate code.

To avoid exposing unnecessary code, I duplicated the function
twice. But let me know if you have strong opinions about this.

https://mattermost.atlassian.net/browse/MM-60171

```release-note
NONE
```


---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Agniva De Sarker
2024-09-25 10:00:14 +05:30
коммит произвёл GitHub
родитель e0e0b57b8b
Коммит 9447cb9074
7 изменённых файлов: 33 добавлений и 62 удалений

Просмотреть файл

@@ -245,12 +245,7 @@ func (s LocalCacheChannelStore) GetMany(ids []string, allowFromCache bool) (mode
var channelsToQuery []string
if allowFromCache {
var toPass []any
for i := 0; i < len(ids); i++ {
var channel *model.Channel
toPass = append(toPass, &channel)
}
toPass := allocateCacheTargets[*model.Channel](len(ids))
errs := s.rootStore.doMultiReadCache(s.rootStore.roleCache, ids, toPass)
for i, err := range errs {
if err != nil {
@@ -352,12 +347,7 @@ func (s LocalCacheChannelStore) getByNames(teamId string, names []string, allowF
newKeys = append(newKeys, teamId+name)
}
toPass := make([]any, 0, len(newKeys))
for i := 0; i < len(newKeys); i++ {
var channel *model.Channel
toPass = append(toPass, &channel)
}
toPass := allocateCacheTargets[*model.Channel](len(newKeys))
errs := s.rootStore.doMultiReadCache(s.rootStore.roleCache, newKeys, toPass)
for i, err := range errs {
if err != nil {
@@ -474,12 +464,7 @@ func (s LocalCacheChannelStore) GetChannelsMemberCount(channelIDs []string) (_ m
counts := make(map[string]int64)
remainingChannels := make([]string, 0)
toPass := make([]any, 0, len(channelIDs))
for i := 0; i < len(channelIDs); i++ {
var cacheItem int64
toPass = append(toPass, &cacheItem)
}
toPass := allocateCacheTargets[int64](len(channelIDs))
errs := s.rootStore.doMultiReadCache(s.rootStore.reaction.rootStore.channelMemberCountsCache, channelIDs, toPass)
for i, err := range errs {
if err != nil {