···221221 let pageCount = 0;
222222 let collectionRecords = [];
223223 let reachedCutoff = false;
224224+ let totalRecordsForCollection = 0;
224225225225- // For initial deep load, we paginate more to get historical data
226226+ // For initial deep load, we need to paginate as many times as needed to get all historical data
226227 // For regular timeline browsing or load more, we just get one page
227227- const maxPages = isInitialDeepLoad ? 20 : 1;
228228+ // Set a high limit for safety, but essentially allow unlimited pagination until we hit the cutoff date
229229+ const maxPages = isInitialDeepLoad ? 1000 : 1;
228230229231 while (hasMoreRecords && pageCount < maxPages && !reachedCutoff) {
230232 // Fetch up to 100 records per page
···249251250252 // Process records from this page
251253 if (data.records && data.records.length > 0) {
254254+ console.log(`Received ${data.records.length} records for ${collection} page ${pageCount}`);
255255+ totalRecordsForCollection += data.records.length;
256256+252257 const processedRecords = data.records.map(record => {
253258 const contentTimestamp = extractTimestamp(record);
254259 const rkey = record.uri.split('/').pop();
···274279 return recordTime < oldest ? recordTime : oldest;
275280 }, Date.now());
276281277277- // If the oldest record on this page is older than our cutoff, we'll stop
278278- if (oldestRecordTime < cutoffDate.getTime()) {
282282+ // For commonly used collections like likes, follows, etc.,
283283+ // we need to be more cautious about when to stop paginating
284284+ const isHighVolumeCollection = collection.includes('like') ||
285285+ collection.includes('follow') ||
286286+ collection.includes('repost');
287287+288288+ // If the oldest record on this page is older than our cutoff, and
289289+ // 1. It's not a high volume collection, OR
290290+ // 2. It's a high volume collection but we've already gone through several pages
291291+ if (oldestRecordTime < cutoffDate.getTime() &&
292292+ (!isHighVolumeCollection || pageCount > 5)) {
279293 reachedCutoff = true;
280280- console.log(`Reached cutoff date for ${collection} on page ${pageCount}`);
294294+ console.log(`Reached cutoff date for ${collection} on page ${pageCount} (oldest: ${new Date(oldestRecordTime).toISOString()})`);
281295282296 // Filter records from this page to only include those after cutoff
283297 const filteredRecords = processedRecords.filter(record => {
···286300 return new Date(timestamp) >= cutoffDate;
287301 });
288302303303+ console.log(` - Kept ${filteredRecords.length} of ${processedRecords.length} records from final page`);
289304 collectionRecords.push(...filteredRecords);
290305 } else {
291291- // All records on this page are within our date range
306306+ // All records on this page are within our date range
307307+ // OR we need to keep paginating through high-volume collections
292308 collectionRecords.push(...processedRecords);
309309+310310+ // If we found some records close to the cutoff date but haven't reached it yet,
311311+ // log this for debugging purposes
312312+ if (oldestRecordTime < cutoffDate.getTime() + (7 * 24 * 60 * 60 * 1000)) { // within 7 days of cutoff
313313+ console.log(` - Getting close to cutoff date, oldest record = ${new Date(oldestRecordTime).toISOString()}`);
314314+ }
293315 }
294316 } else {
295317 // For regular browsing, include all records from the page
···316338 } else {
317339 // No more records for this collection
318340 delete newCursors[collection];
341341+ }
342342+343343+ console.log(`Finished fetching ${collection}: Retrieved ${totalRecordsForCollection} records in ${pageCount} pages`);
344344+ console.log(` - After filtering: ${collectionRecords.length} records in 90-day window`);
345345+ if (reachedCutoff) {
346346+ console.log(` - Stopped because records older than 90 days were found`);
347347+ } else if (!cursor) {
348348+ console.log(` - Stopped because no more records were available`);
349349+ } else if (pageCount >= maxPages) {
350350+ console.log(` - Stopped because max page limit (${maxPages}) was reached`);
319351 }
320352321353 // Add records to appropriate arrays
···358390 displayRecords = filterAndSort(allRecords);
359391 }
360392361361- console.log(`Fetched ${sortedChartRecords.length} records for chart, showing ${displayRecords.length} in timeline`);
393393+ // Create a summary of records per collection for debugging
394394+ const collectionSummary = {};
395395+ sortedChartRecords.forEach(record => {
396396+ if (!collectionSummary[record.collection]) {
397397+ collectionSummary[record.collection] = 0;
398398+ }
399399+ collectionSummary[record.collection]++;
400400+ });
401401+402402+ console.log("Collection record counts in 90-day period:");
403403+ Object.entries(collectionSummary)
404404+ .sort((a, b) => b[1] - a[1]) // Sort by count descending
405405+ .forEach(([collection, count]) => {
406406+ console.log(` - ${collection}: ${count} records`);
407407+ });
408408+409409+ console.log(`Fetched ${sortedChartRecords.length} total records for chart, showing ${displayRecords.length} in timeline`);
362410363411 // Update state
364412 setRecords(displayRecords);