From 2a20b281c7015302424602421926eb463c694703 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 12 Feb 2020 13:30:35 +0900 Subject: [PATCH] Improved performance and less shadowing --- pages/soundtrack/soundtrack.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pages/soundtrack/soundtrack.go b/pages/soundtrack/soundtrack.go index b3ac9e4f..26854738 100644 --- a/pages/soundtrack/soundtrack.go +++ b/pages/soundtrack/soundtrack.go @@ -13,14 +13,16 @@ import ( func Get(ctx aero.Context) error { id := ctx.Get("id") track, err := arn.GetSoundTrack(id) - user := arn.GetUserFromContext(ctx) if err != nil { return ctx.Error(http.StatusNotFound, "Track not found", err) } + user := arn.GetUserFromContext(ctx) + animes := track.Anime() + relatedTracks := arn.FilterSoundTracks(func(t *arn.SoundTrack) bool { - return !t.IsDraft && len(t.Media) > 0 && t.ID != track.ID && isRelated(track.Anime(), t) + return !t.IsDraft && len(t.Media) > 0 && t.ID != track.ID && isRelated(animes, t) }) customCtx := ctx.(*middleware.OpenGraphContext) @@ -28,8 +30,8 @@ func Get(ctx aero.Context) error { return ctx.HTML(components.SoundTrackPage(track, relatedTracks, user)) } -func isRelated(anime []*arn.Anime, track *arn.SoundTrack) bool { - for _, anime := range anime { +func isRelated(animes []*arn.Anime, track *arn.SoundTrack) bool { + for _, anime := range animes { if arn.Contains(track.Tags, "anime:"+anime.ID) { return true }