mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-10-25 04:32:10 +08:00
Merge 8cd57d68535f83c6495423e777f6a30c88cbe0f1 into bf0289075b1bc42b597331ea0cff809752449721
This commit is contained in:
commit
849e32c622
31
pkg/common/storage/cache/redis/batch.go
vendored
31
pkg/common/storage/cache/redis/batch.go
vendored
@ -76,6 +76,27 @@ func batchGetCache2[K comparable, V any](ctx context.Context, rcClient *rocksCac
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
values, err := fn(ctx, ids)
|
||||||
|
if err != nil {
|
||||||
|
log.ZError(ctx, "batchGetCache query database failed", err, "ids", ids)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
idToValue := make(map[K]*V)
|
||||||
|
for _, value := range values {
|
||||||
|
idToValue[vId(value)] = value
|
||||||
|
}
|
||||||
|
getSlotValues := func(slotIds []K) []*V {
|
||||||
|
if len(slotIds) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
slotValues := make([]*V, 0, len(slotIds))
|
||||||
|
for _, id := range slotIds {
|
||||||
|
if value, ok := idToValue[id]; ok {
|
||||||
|
slotValues = append(slotValues, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return slotValues
|
||||||
|
}
|
||||||
result := make([]*V, 0, len(findKeys))
|
result := make([]*V, 0, len(findKeys))
|
||||||
for _, keys := range slotKeys {
|
for _, keys := range slotKeys {
|
||||||
indexCache, err := rcClient.GetClient().FetchBatch2(ctx, keys, expire, func(idx []int) (map[int]string, error) {
|
indexCache, err := rcClient.GetClient().FetchBatch2(ctx, keys, expire, func(idx []int) (map[int]string, error) {
|
||||||
@ -86,16 +107,12 @@ func batchGetCache2[K comparable, V any](ctx context.Context, rcClient *rocksCac
|
|||||||
idIndex[id] = index
|
idIndex[id] = index
|
||||||
queryIds = append(queryIds, id)
|
queryIds = append(queryIds, id)
|
||||||
}
|
}
|
||||||
values, err := fn(ctx, queryIds)
|
slotValues := getSlotValues(queryIds)
|
||||||
if err != nil {
|
if len(slotValues) == 0 {
|
||||||
log.ZError(ctx, "batchGetCache query database failed", err, "keys", keys, "queryIds", queryIds)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if len(values) == 0 {
|
|
||||||
return map[int]string{}, nil
|
return map[int]string{}, nil
|
||||||
}
|
}
|
||||||
cacheIndex := make(map[int]string)
|
cacheIndex := make(map[int]string)
|
||||||
for _, value := range values {
|
for _, value := range slotValues {
|
||||||
id := vId(value)
|
id := vId(value)
|
||||||
index, ok := idIndex[id]
|
index, ok := idIndex[id]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user