more core/user refactor

This commit is contained in:
perennial
2024-10-23 14:16:12 +11:00
parent be2fa65276
commit 79d7567904
+21 -21
View File
@@ -177,25 +177,6 @@ func getPopulatedWorks(auditor *audit.Auditor, r *http.Request, user *User, id s
zap.Bool("getTags", getTags),
)
auditor.Logger.Debug("Fetching bookmarks")
// Fetch bookmarks
works, count, err := fetchBookmarks(auditor, r, id, "show", page)
if err != nil {
auditor.SugaredLogger.Error("Failed to fetch bookmarks", zap.Error(err))
return err
}
user.Categories["bookmarks"].IllustWorks = works
user.Categories["bookmarks"].WorkCount = count
auditor.Logger.Debug("Bookmarks fetched", zap.Int("count", count), zap.Int("worksCount", len(works)))
// Calculate PageLimit for bookmarks
worksPerPage := 48.0
pageLimit := int(math.Ceil(float64(count) / worksPerPage))
user.Categories["bookmarks"].SetPageLimit(pageLimit)
auditor.Logger.Debug("PageLimit set for bookmarks", zap.Int("pageLimit", pageLimit))
// Fetch work IDs and series data
auditor.Logger.Debug("Fetching work IDs and series data for works")
categoriesData, err := fetchWorkIDsAndSeriesData(auditor, r, id, currentCategory, page)
@@ -212,7 +193,7 @@ func getPopulatedWorks(auditor *audit.Auditor, r *http.Request, user *User, id s
// Fetch and populate works for each category
for _, cat := range user.Categories {
if cat.WorkIDs == "" {
if cat.WorkIDs == "" && cat.Value != "bookmarks" {
continue
}
@@ -234,6 +215,18 @@ func getPopulatedWorks(auditor *audit.Auditor, r *http.Request, user *User, id s
return err
}
cat.NovelWorks = novels
case "bookmarks":
auditor.Logger.Debug("Fetching and populating Bookmarks", zap.String("category", cat.Value))
bookmarks, count, err := fetchBookmarks(auditor, r, id, "show", page)
if err != nil {
auditor.SugaredLogger.Error("Failed to fetch bookmarks", zap.Error(err))
return err
}
cat.IllustWorks = bookmarks
cat.WorkCount = count
worksPerPage := 48.0
cat.PageLimit = int(math.Ceil(float64(count) / worksPerPage))
}
// Handle series data
@@ -245,7 +238,7 @@ func getPopulatedWorks(auditor *audit.Auditor, r *http.Request, user *User, id s
}
// Fetch frequent tags if requested
if getTags {
if getTags && cat.Value != "bookmarks" {
auditor.Logger.Debug("Fetching frequent tags for category", zap.String("category", cat.Value))
tags, err := fetchFrequentTags(auditor, r, cat.WorkIDs, cat)
if err != nil {
@@ -357,6 +350,13 @@ func fetchWorkIDsAndSeriesData(auditor *audit.Auditor, r *http.Request, id strin
}
categories["novels"] = novelCat
// Create an empty bookmarks category
//
// We don't build an ID string here as fetchBookmarks populates IllustWorks without the need for a WorkIDs string
// (which is also why we can't call fetchFrequentTags for the "bookmarks" category, though extracting the IDs from
// ArtworkBrief would be possible)
categories["bookmarks"] = &UserWorkCategory{Value: "bookmarks"}
return categories, nil
}