From 09aabcf1e59955960249e402ea1f32558abb2a05 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Mon, 14 Nov 2022 18:46:50 +0100 Subject: [PATCH] Preload history videos on home appear --- Shared/Home/HistoryView.swift | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Shared/Home/HistoryView.swift b/Shared/Home/HistoryView.swift index 1969ad32..ef969242 100644 --- a/Shared/Home/HistoryView.swift +++ b/Shared/Home/HistoryView.swift @@ -1,6 +1,8 @@ import SwiftUI struct HistoryView: View { + static let detailsPreloadLimit = 50 + @FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)]) var watches: FetchedResults @@ -15,7 +17,6 @@ struct HistoryView: View { HStack { Image(systemName: "clock") Text("Playback history is empty") - }.foregroundColor(.secondary) } } else { @@ -24,15 +25,18 @@ struct HistoryView: View { item: PlayerQueueItem.from(watch, video: player.historyVideo(watch.videoID)), history: true ) - .onAppear { - player.loadHistoryVideoDetails(watch.videoID) - } .contextMenu { VideoContextMenuView(video: player.historyVideo(watch.videoID) ?? watch.video) } } } } + .onAppear { + visibleWatches + .prefix(Self.detailsPreloadLimit) + .map(\.videoID) + .forEach(player.loadHistoryVideoDetails) + } #if os(tvOS) .padding(.horizontal, 40) #else