From 992ff969cf499cefb2a851c996b74a28e827b727 Mon Sep 17 00:00:00 2001 From: everpcpc Date: Mon, 25 Nov 2024 22:13:41 +0800 Subject: [PATCH] fix: return empty for empty tag request --- internal/tag/cache_repo.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/tag/cache_repo.go b/internal/tag/cache_repo.go index b1ca5e19..74c6ab70 100644 --- a/internal/tag/cache_repo.go +++ b/internal/tag/cache_repo.go @@ -74,6 +74,11 @@ func (r cacheRepo) Get(ctx context.Context, id model.SubjectID) ([]Tag, error) { func (r cacheRepo) GetByIDs(ctx context.Context, ids []model.SubjectID) (map[model.SubjectID][]Tag, error) { var tags []cachedTags + result := make(map[model.SubjectID][]Tag, len(ids)) + if len(ids) == 0 { + return result, nil + } + err := r.cache.MGet(ctx, lo.Map(ids, func(item model.SubjectID, index int) string { return cachekey.SubjectMetaTag(item) }), &tags) @@ -81,7 +86,6 @@ func (r cacheRepo) GetByIDs(ctx context.Context, ids []model.SubjectID) (map[mod return nil, errgo.Wrap(err, "cache.MGet") } - result := make(map[model.SubjectID][]Tag, len(ids)) for _, tag := range tags { result[tag.ID] = tag.Tags }