diff --git a/core/user.go b/core/user.go index bc69764..11cb969 100644 --- a/core/user.go +++ b/core/user.go @@ -224,18 +224,36 @@ func fetchUserWorks(r *http.Request, user *User, id string, category UserWorkCat // Fetch frequent tags if requested if getTags { - var tagsIDs string + var tagsIDs []string // TODO: frequent tags for novels are *not* fetched when CategoryAny or CategoryAnyAlt + + // Since category is pre-validated, we don't need to handle unexpected categories if category == CategoryAny || category == CategoryAnyAlt || category == CategoryIllustration || category == CategoryManga { - tagsIDs = illustrationIDs + mangaIDs - } else { - tagsIDs = novelIDs + // Append illustrationIDs and mangaIDs if they are not empty + if illustrationIDs != "" { + tagsIDs = append(tagsIDs, illustrationIDs) + } + if mangaIDs != "" { + tagsIDs = append(tagsIDs, mangaIDs) + } + } else if category == CategoryNovels { + // Append novelIDs if not empty + if novelIDs != "" { + tagsIDs = append(tagsIDs, novelIDs) + } } - user.FrequentTags, err = getUserFrequentTags(r, tagsIDs, category) - if err != nil { - return err + if len(tagsIDs) == 0 { + // No tags to fetch, set FrequentTags to empty slice + user.FrequentTags = []FrequentTag{} + } else { + // Concatenate IDs with commas to form a single string + ids := strings.Join(tagsIDs, ",") + user.FrequentTags, err = getUserFrequentTags(r, ids, category) + if err != nil { + return fmt.Errorf("failed to get user frequent tags: %w", err) + } } }