diff --git a/apps/electron-backend/src/app/database/operations/favorites.operations.spec.ts b/apps/electron-backend/src/app/database/operations/favorites.operations.spec.ts index 7c3df2120..6db591360 100644 --- a/apps/electron-backend/src/app/database/operations/favorites.operations.spec.ts +++ b/apps/electron-backend/src/app/database/operations/favorites.operations.spec.ts @@ -23,6 +23,9 @@ function createGlobalFavoritesDbMock(rows: unknown[]) { innerJoin: jest.fn(), limit: jest.fn(), orderBy: jest.fn(), + then: jest.fn((resolve, reject) => + Promise.resolve(rows).then(resolve, reject) + ), where: whereMock, }; query.from.mockReturnValue(query); @@ -48,7 +51,7 @@ describe('favorites.operations', () => { }); it('filters live global favorites after scanning the small favorites set', async () => { - const { db } = createGlobalFavoritesDbMock([ + const { db, query } = createGlobalFavoritesDbMock([ { id: 1, title: 'Saved Movie', @@ -64,6 +67,7 @@ describe('favorites.operations', () => { const result = await getGlobalFavorites(db); expect(whereMock).not.toHaveBeenCalled(); + expect(query.limit).not.toHaveBeenCalled(); expect(result).toEqual([ expect.objectContaining({ id: 2, diff --git a/apps/electron-backend/src/app/database/operations/favorites.operations.ts b/apps/electron-backend/src/app/database/operations/favorites.operations.ts index 830653f6b..c0b402a63 100644 --- a/apps/electron-backend/src/app/database/operations/favorites.operations.ts +++ b/apps/electron-backend/src/app/database/operations/favorites.operations.ts @@ -10,7 +10,6 @@ import { import { persistContentBackdropIfMissing } from './content-backdrop.operations'; const DEFAULT_BATCH_SIZE = 100; -const GLOBAL_LIVE_FAVORITES_SCAN_LIMIT = 2000; export async function addFavorite( db: AppDatabase, @@ -92,7 +91,7 @@ export async function getFavorites(db: AppDatabase, playlistId: string) { export async function getGlobalFavorites(db: AppDatabase) { const favorites = await selectGlobalFavoriteRows(db, { includeBackdrop: false, - }).limit(GLOBAL_LIVE_FAVORITES_SCAN_LIMIT); + }); return favorites.filter((favorite) => favorite.type === 'live').slice(0, 300); } diff --git a/libs/workspace/dashboard/data-access/src/lib/dashboard-data.service.spec.ts b/libs/workspace/dashboard/data-access/src/lib/dashboard-data.service.spec.ts index ca50a1300..7db523906 100644 --- a/libs/workspace/dashboard/data-access/src/lib/dashboard-data.service.spec.ts +++ b/libs/workspace/dashboard/data-access/src/lib/dashboard-data.service.spec.ts @@ -449,6 +449,8 @@ describe('DashboardDataService', () => { expect.objectContaining({ title: 'Channel Two' }), ]) ); + expect(service.globalFavoritesLoaded()).toBe(true); + expect(service.globalFavoritesLoading()).toBe(false); }); it('keeps the earliest matching M3U favorite id when channel id and URL both match', async () => { diff --git a/libs/workspace/dashboard/data-access/src/lib/dashboard-data.service.ts b/libs/workspace/dashboard/data-access/src/lib/dashboard-data.service.ts index 83cbe91df..989c839cd 100644 --- a/libs/workspace/dashboard/data-access/src/lib/dashboard-data.service.ts +++ b/libs/workspace/dashboard/data-access/src/lib/dashboard-data.service.ts @@ -542,6 +542,12 @@ export class DashboardDataService { const m3uReload = this.reloadPlaylistBackedGlobalFavorites(); await Promise.all([xtreamReload, m3uReload]); + if ( + this.playlistsLoaded() && + !this.playlistBackedGlobalFavoritesLoadedState() + ) { + await this.reloadPlaylistBackedGlobalFavorites(); + } this.finishInitialGlobalFavoritesLoadIfReady(); this.favoritesAutoRefreshEnabled.set(true); } @@ -1212,17 +1218,14 @@ export class DashboardDataService { const fallbackTimestamp = this.getM3uFavoriteTimestamp(playlistMeta) ?? new Date(0).toISOString(); - const items = resolvedChannels - .slice() - .sort((a, b) => a.favoriteIndex - b.favoriteIndex) - .map((favorite) => - this.createM3uFavoriteItem( - playlistMeta, - favorite.favoriteId, - favorite.channel, - fallbackTimestamp - ) - ); + const items = resolvedChannels.slice().map((favorite) => + this.createM3uFavoriteItem( + playlistMeta, + favorite.favoriteId, + favorite.channel, + fallbackTimestamp + ) + ); this.m3uFavoritesCache.set(playlistMeta._id, { fingerprint,