Explicit PrefetchAnime call

This commit is contained in:
Eduard Urbach 2017-07-05 14:34:33 +02:00
parent 9d28c652c0
commit a94b69d671
5 changed files with 6 additions and 15 deletions

View File

@ -29,6 +29,7 @@ func BenchmarkRenderThread(b *testing.B) {
func BenchmarkRenderAnimeList(b *testing.B) { func BenchmarkRenderAnimeList(b *testing.B) {
user, _ := arn.GetUser("4J6qpK1ve") user, _ := arn.GetUser("4J6qpK1ve")
animeList := user.AnimeList() animeList := user.AnimeList()
animeList.PrefetchAnime()
b.ReportAllocs() b.ReportAllocs()
b.ResetTimer() b.ResetTimer()

View File

@ -25,6 +25,7 @@ func Get(ctx *aero.Context) string {
return ctx.Error(http.StatusNotFound, "Anime list not found", nil) return ctx.Error(http.StatusNotFound, "Anime list not found", nil)
} }
animeList.PrefetchAnime()
animeList.Sort() animeList.Sort()
return ctx.HTML(components.AnimeLists(animeList.SplitByStatus(), animeList.User(), user)) return ctx.HTML(components.AnimeLists(animeList.SplitByStatus(), animeList.User(), user))

View File

@ -47,27 +47,14 @@ func dashboard(ctx *aero.Context) string {
} }
animeList = animeList.WatchingAndPlanned() animeList = animeList.WatchingAndPlanned()
animeList.PrefetchAnime()
var keys []string
for _, item := range animeList.Items { for _, item := range animeList.Items {
keys = append(keys, item.AnimeID)
}
objects, getErr := arn.DB.GetMany("Anime", keys)
if getErr != nil {
return
}
allAnimeInList := objects.([]*arn.Anime)
for _, anime := range allAnimeInList {
if len(upcomingEpisodes) >= maxScheduleItems { if len(upcomingEpisodes) >= maxScheduleItems {
break break
} }
futureEpisodes := anime.UpcomingEpisodes() futureEpisodes := item.Anime().UpcomingEpisodes()
if len(futureEpisodes) == 0 { if len(futureEpisodes) == 0 {
continue continue

View File

@ -23,6 +23,7 @@ func Get(ctx *aero.Context) string {
} }
watchingList := animeList.WatchingAndPlanned() watchingList := animeList.WatchingAndPlanned()
watchingList.PrefetchAnime()
watchingList.Sort() watchingList.Sort()
return utils.AllowEmbed(ctx, ctx.HTML(components.AnimeList(watchingList, animeList.User(), user))) return utils.AllowEmbed(ctx, ctx.HTML(components.AnimeList(watchingList, animeList.User(), user)))

View File

@ -35,6 +35,7 @@ func Profile(ctx *aero.Context, viewUser *arn.User) string {
user = utils.GetUser(ctx) user = utils.GetUser(ctx)
}, func() { }, func() {
animeList = viewUser.AnimeList() animeList = viewUser.AnimeList()
animeList.PrefetchAnime()
}) })
return ctx.HTML(components.Profile(viewUser, user, animeList, threads, posts, tracks)) return ctx.HTML(components.Profile(viewUser, user, animeList, threads, posts, tracks))