This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

add pagination to record fetching

+33 -12
+33 -12
app/src/app/profile/[handle]/page.tsx
··· 139 139 console.log(`Using PDS endpoint: ${serviceEndpoint}`); 140 140 141 141 // Step 3: Fetch records from PDS 142 - const listRecordsUrl = `${serviceEndpoint}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(did)}&collection=im.flushing.right.now&limit=100`; 143 - console.log(`Fetching records from: ${listRecordsUrl}`); 142 + let allRecords: any[] = []; 143 + let cursor: string | undefined; 144 + let hasMore = true; 144 145 145 - const recordsResponse = await fetch(listRecordsUrl, { 146 - headers: { 147 - 'Accept': 'application/json' 146 + while (hasMore) { 147 + const listRecordsUrl = `${serviceEndpoint}/xrpc/com.atproto.repo.listRecords?repo=${encodeURIComponent(did)}&collection=im.flushing.right.now&limit=100${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ''}`; 148 + console.log(`Fetching records from: ${listRecordsUrl}`); 149 + 150 + const recordsResponse = await fetch(listRecordsUrl, { 151 + headers: { 152 + 'Accept': 'application/json' 153 + } 154 + }); 155 + 156 + if (!recordsResponse.ok) { 157 + throw new Error(`Failed to fetch records: ${recordsResponse.statusText}`); 158 + } 159 + 160 + const recordsData = await recordsResponse.json(); 161 + console.log(`Fetched ${recordsData.records.length} records${cursor ? ' (next page)' : ''}`); 162 + 163 + // Add records to our collection 164 + allRecords = [...allRecords, ...recordsData.records]; 165 + 166 + // Check if we have more pages 167 + cursor = recordsData.cursor; 168 + hasMore = !!cursor && recordsData.records.length === 100; 169 + 170 + if (hasMore) { 171 + console.log(`More records available, cursor: ${cursor}`); 172 + } else { 173 + console.log('No more records to fetch'); 148 174 } 149 - }); 150 - 151 - if (!recordsResponse.ok) { 152 - throw new Error(`Failed to fetch records: ${recordsResponse.statusText}`); 153 175 } 154 176 155 - const recordsData = await recordsResponse.json(); 156 - console.log('Records data:', recordsData); 177 + console.log(`Total records fetched: ${allRecords.length}`); 157 178 158 179 // Transform the records into our format 159 - const userEntries = recordsData.records 180 + const userEntries = allRecords 160 181 .map((record: any) => { 161 182 const text = record.value.text || ''; 162 183 if (containsBannedWords(text)) return null;