fix bad getTags code

This commit is contained in:
perennial
2024-10-20 00:10:51 +11:00
parent 6ae13d11a0
commit 05ce3f0964
+25 -7
View File
@@ -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)
}
}
}