diff --git a/materialious/src/lib/api/youtubejs/subscriptions.ts b/materialious/src/lib/api/youtubejs/subscriptions.ts index 125406ff..d3126752 100644 --- a/materialious/src/lib/api/youtubejs/subscriptions.ts +++ b/materialious/src/lib/api/youtubejs/subscriptions.ts @@ -126,6 +126,8 @@ export async function parseChannelRSS(channelId: string): Promise { } } +// Ignored to match non ytjs version of getfeed. +// eslint-disable-next-line @typescript-eslint/no-unused-vars export async function getFeedYTjs(maxResults: number, page: number): Promise { const channelSubscriptions = await localDb.channelSubscriptions.toArray(); @@ -133,20 +135,25 @@ export async function getFeedYTjs(maxResults: number, page: number): Promise oneDayInMillis) { parseChannelRSS(channel.channelId); } } - const offset = (page - 1) * maxResults; + const videos = await localDb.subscriptionFeed.toArray(); + videos.sort((a, b) => b.published - a.published); + + // Cull videos if there are more than 1000 + if (videos.length > 1000) { + const videosToDelete = videos.slice(1000); + const videoIdsToDelete = videosToDelete.map((video) => video.videoId); + + await localDb.subscriptionFeed.where('id').anyOf(videoIdsToDelete).delete(); + } return { notifications: [], - videos: await localDb.subscriptionFeed.toArray().then((videos) => { - videos.sort((a, b) => b.published - a.published); - const paginatedVideos = videos.slice(offset, offset + maxResults); - return paginatedVideos; - }) + videos: videos }; }