fix(pwa): prefer xtream collection snapshots

This commit is contained in:
4gray committed 2026-05-21 21:13:58 +03:00
1 parent 87dfaec03d
commit 69b7bca9df
1 file changed
+17 -10
@@ -467,14 +467,12 @@ export class PwaXtreamDataSource implements IXtreamDataSource {
async getFavorites(playlistId: string): Promise<XtreamContentItem[]> {
const allFavorites = this.getFavoritesFromStorage();
const playlistFavorites = allFavorites[playlistId] || [];
await this.hydrateStoredCollectionContent(
const contentById = await this.getCollectionItemsWithHydration(
playlistId,
playlistFavorites
);
return Array.from(
this.getCollectionItemsById(playlistId, playlistFavorites).values()
);
return Array.from(contentById.values());
}
async addFavorite(
@@ -684,12 +682,7 @@ export class PwaXtreamDataSource implements IXtreamDataSource {
async getRecentItems(playlistId: string): Promise<XtreamContentItem[]> {
const allRecent = this.getRecentItemsFromStorage();
const playlistRecent = allRecent[playlistId] || [];
await this.hydrateStoredCollectionContent(
playlistId,
playlistRecent.map((item) => item.id)
);
const contentById = this.getCollectionItemsById(
const contentById = await this.getCollectionItemsWithHydration(
playlistId,
playlistRecent.map((item) => item.id)
);
@@ -999,6 +992,20 @@ export class PwaXtreamDataSource implements IXtreamDataSource {
return results;
}
private async getCollectionItemsWithHydration(
playlistId: string,
ids: readonly number[]
): Promise<Map<number, XtreamContentItem>> {
const contentById = this.getCollectionItemsById(playlistId, ids);
const missingIds = ids.filter((id) => !contentById.has(id));
if (missingIds.length === 0) {
return contentById;
}
await this.hydrateStoredCollectionContent(playlistId, missingIds);
return this.getCollectionItemsById(playlistId, ids);
}
private findCachedContentItemById(
playlistId: string,
contentId: number