Repository navigation
fix(traffic): read Search Console pages a week at a time, and resume their backfill - #1253
Conversation
…their backfill Each 28-day [page, date] pull stopped at the 25,000-row cap ordered by clicks, so on a large site the dropped rows were zero-click page-days, and recent days, re-read daily, kept more of them than older days read once. The page sync now pulls a week at a time (PAGE_WINDOW_DAYS), so the cap falls evenly. The 190-day backfill restarted from the newest window on every run until one got through, so a window that kept failing made every daily run read the whole history again. 00201 adds brands.gsc_pages_backfill_from, the oldest day read so far, kept after each window: a sync cut short resumes after it the next day. gsc_pages_backfilled_property now names the property the page rows belong to, set once its last 28 days are in; a brand backfilled before reads as done, and a new property still drops the old one's pages first. Follow-up to ansvisor#1177's review. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
@gkhngyk the remaining #1177 notes: page pulls go a week at a time, and the 190-day backfill keeps how far back it has read ( |
schema.sql is rebuilt with build-schema.sh after 00202 landed. Claude-Session: https://claude.ai/code/session_0121amRjX7UFrgmGELAtkc7A
gkhngyk
left a comment
There was a problem hiding this comment.
Looks good. I walked the resume through by hand. A window stores its oldest day; the next day that day is one day older, and pageWindows(readTo + 1, …) starts on the day before it, so no day is skipped and none is read twice. A brand backfilled before this PR reads as done, and a new property still drops the old one's rows.
Tested with #1254 and #1255 on main: server 1,914 tests pass, and tsc, lint and Prettier are clean. 00201 is applied to production, ahead of the server deploy, since the brand query selects the new column.
Worth knowing: a daily page sync is now about five Composio calls per brand instead of one, and a first backfill about 24.
Summary
Follow-up from #1177's review (non-blocking notes):
[page, date]pull stops at 25,000 rows ordered by clicks, so on a large site the zero-click page-days are what's dropped … Pulling a day or a week at a time spreads the cap evenly."(The third note, an index for the prune's
date < …, is already there:gsc_page_stats_date_idxin 00181.)A week at a time (
server/src/lib/gsc-sync.js)PAGE_WINDOW_DAYS = 7.Resume the backfill (migration 00201,
brands.gsc_pages_backfill_from date)gsc_pages_backfill_fromis the oldest day the property's backfill has read so far, kept after each window. It is null once the backfill is through.gsc_pages_backfilled_propertynow names the property the page rows belong to. It is set once the property's last 28 days are in, so a first sync that stops before that starts over without leaving a gap.API calls: a daily sync makes about five page calls instead of one. A first backfill makes about 24 small ones instead of seven. Each is one page of up to 5,000 rows unless a week is larger.
Deploy: apply 00201 before the server, since the brand query selects the new column. As with 00181, migrations are applied at merge.
Numbering: main has 00196, 00198 and 00199. Open PRs: 00197 #1243, 00200 #1247, plus 00190/00191/00194/00195.
schema.sqlhere is main at 8ee1044 plus 00201.Related issue
Follow-up to #1177.
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsHow to test
Unit tests
gsc-sync.test.js:pageWindowscovers the range a week at a time with no gap;pagesSyncPlancovers a new property, done, resuming from a stored day, reaching 190 days, and a changed property.gsc-sync-pages.test.js(new) runsrunGscSyncover mocked Composio and Supabase:Dev DB: 00201 applied;
brands.gsc_pages_backfill_fromexists. There is no Search Console connection locally, so a real-account run would be welcome.Checklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)Also: server
npm run lint,npm test(1902); webyarn test(1796) andyarn build(onlytypes/supabase.tschanged there);bash supabase/build-schema.sh.🤖 Generated with Claude Code