Fix YouTube history pagination stuck in a loop#113
Closed
micahmo wants to merge 2 commits intoaizhimou:mainfrom
Closed
Fix YouTube history pagination stuck in a loop#113micahmo wants to merge 2 commits intoaizhimou:mainfrom
micahmo wants to merge 2 commits intoaizhimou:mainfrom
Conversation
Author
|
Was this issue solved in b54eebb by switching to cursor-based pagination? |
Owner
|
I did not end up taking the PR code directly, because I chose to solve this by upgrading the metadata storage model rather than applying a narrower patch on top of the previous behavior. That said, your investigation and PR were genuinely helpful and helped point us in the right direction, so thank you for that. |
Owner
Yes, I think it does. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please choose the "Hide whitespace" option when reviewing.
Fix "Load more episodes from YouTube" getting stuck in a loop (issue #109)
"Load more episodes from YouTube" would repeatedly fetch the same page, either adding duplicate episodes or looping forever instead of advancing to older content.
Root cause
The "Load more episodes" button only appears for Channel subscriptions (not Playlists). The next YouTube API page was computed in
ChannelServiceasceil(savedEpisodeCount / 50) + 1. Two failure modes:saveEpisodes()skips duplicates,totalCountdoesn't change, next click computes the sametargetPage→ infinite loop fetching the same page.ceil(53/50) + 1 = page 2again.Additionally, the return value included ALL episodes from the YouTube API page (including ones already in the DB), causing the frontend to show "Loaded 6 historical episodes" and append duplicate entries to the list.
Fix: persist
history_page_indexon the ChannelInstead of recomputing from DB count, store which YouTube API page was last fetched and always advance it by 1 — regardless of how many items matched or were new.
When a page contains only episodes already in the DB (e.g. due to the migration seed value slightly under-counting pages consumed during init), the method automatically skips forward to the next page (up to 5 consecutive skips) so the user doesn't have to click "Load more" through already-known pages.
V36__Add_channel_history_page_index.sqlhistory_page_index INTEGER NOT NULL DEFAULT 0tochanneltable; seeds existing channels viaceil(episode_count / 50)so first "Load more" targets the correct next pageChannel.javahistoryPageIndexfieldChannelService.fetchChannelHistoryhistoryPageIndex + 1; persists incremented value on every call (hit or miss); auto-skips pages with all duplicates; returns only truly-new episodes viafilterNewEpisodes()✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.