Avoid calling FilterSoundTracks
for every Anime
as it can potentially be costly
This commit is contained in:
parent
d0135e93ee
commit
8c5ddec450
@ -19,16 +19,21 @@ func Get(ctx aero.Context) error {
|
||||
return ctx.Error(http.StatusNotFound, "Track not found", err)
|
||||
}
|
||||
|
||||
relatedTracks := make([]*arn.SoundTrack, 0, 5)
|
||||
for _, anime := range track.Anime() {
|
||||
anime := anime
|
||||
tracks := arn.FilterSoundTracks(func(t *arn.SoundTrack) bool {
|
||||
return !t.IsDraft && len(t.Media) > 0 && t.ID != track.ID && arn.Contains(t.Tags, "anime:"+anime.ID)
|
||||
relatedTracks := arn.FilterSoundTracks(func(t *arn.SoundTrack) bool {
|
||||
return !t.IsDraft && len(t.Media) > 0 && t.ID != track.ID && isRelated(track.Anime(), t)
|
||||
})
|
||||
relatedTracks = append(relatedTracks, tracks...)
|
||||
}
|
||||
|
||||
customCtx := ctx.(*middleware.OpenGraphContext)
|
||||
customCtx.OpenGraph = getOpenGraph(track)
|
||||
return ctx.HTML(components.SoundTrackPage(track, relatedTracks, user))
|
||||
}
|
||||
|
||||
func isRelated(anime []*arn.Anime, track *arn.SoundTrack) bool {
|
||||
for _, anime := range anime {
|
||||
if arn.Contains(track.Tags, "anime:"+anime.ID) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user