ReviewOS

also looking at this

stacks/analyticshq

fix(dashboard): unshadow the bridged range so site switching works

#54
Merged glennmichael123 wants to merge fix/switch-site-range into main
2 files +45 -3
resources/views/dashboard.stxmodified+5-3
Changes to resources/views/dashboard.stx
@@ -1731,15 +1731,17 @@ async function importFromFathom(): Promise<void> {
17311731 else if (first.status === 413 && first.data.range?.from) {
17321732 // Too big for one request. Post the SAME files again in date windows,
17331733 // sized from the estimate the server just sent back.
1734 const range = first.data.range
1734 // Not `range`: that name reaches this block from the server for switchSite,
1735 // and the bridge withholds any name the block declares, even nested like this.
1736 const importRange = first.data.range
17351737 const total = Number(first.data.estimate?.pageViews ?? 0)
17361738 const max = Number(first.data.maxRows ?? 50000)
1737 const span = fathomWindows(range.from, range.to, 3650)[0]
1739 const span = fathomWindows(importRange.from, importRange.to, 3650)[0]
17381740 const allDays = Math.round((new Date(`${span[1]}T00:00:00Z`).getTime() - new Date(`${span[0]}T00:00:00Z`).getTime()) / 86400000) + 1
17391741 // Two thirds of the cap per window, so an uneven distribution across the
17401742 // range does not push one window back over it.
17411743 const perWindow = Math.max(1, Math.floor(allDays * ((max * 0.66) / Math.max(total, 1))))
1742 const windows = fathomWindows(range.from, range.to, perWindow)
1744 const windows = fathomWindows(importRange.from, importRange.to, perWindow)
17431745
17441746 for (let i = 0; i < windows.length; i++) {
17451747 const [fromDay, toDay] = windows[i]