This repository has no description
0

Configure Feed

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

fix feed data

+68 -23
+36 -15
app/src/app/api/bluesky/feed/route.ts
··· 202 202 } 203 203 } 204 204 205 - // IMPORTANT: We're disabling the cache completely to ensure we always get fresh data 206 - // This is because we're having issues with stale data 207 - if (false && !forceRefresh && now - lastFetchTime < CACHE_TTL && cachedEntries.length > 0) { 205 + // We're completely disabling server-side caching to ensure we always get fresh data 206 + // This is because we've been having issues with stale data 207 + // In a future update, we may re-enable caching with proper invalidation 208 + if (false) { // This condition will never be true 208 209 console.log('Returning cached entries'); 209 210 return NextResponse.json({ entries: cachedEntries }); 210 211 } ··· 223 224 console.log(`Querying database for latest ${MAX_ENTRIES} entries at ${new Date().toISOString()}...`); 224 225 225 226 // Debug log the SQL query we're about to execute 226 - console.log('SQL Query: SELECT id, uri, cid, did, text, emoji, created_at, handle FROM flushing_records ORDER BY created_at DESC LIMIT 20'); 227 + console.log('SQL Query: SELECT id, uri, cid, did, text, emoji, created_at, handle FROM flushing_records ORDER BY id DESC LIMIT 20'); 227 228 228 229 // First, let's check what's the highest ID in the database to debug 229 230 const { data: maxIdResult } = await supabase ··· 252 253 let entries; 253 254 254 255 try { 255 - // First try: Get entries with highest IDs 256 - const { data: idSortedEntries, error: idSortError } = await supabase 256 + // Direct SQL query to get the most recent entries by ID 257 + const { data: directSqlEntries, error: directSqlError } = await supabase 257 258 .from('flushing_records') 258 259 .select('*') 259 260 .order('id', { ascending: false }) 260 261 .limit(MAX_ENTRIES); 261 - 262 - if (idSortError) { 263 - throw idSortError; 262 + 263 + if (directSqlError) { 264 + console.error('❌ Direct SQL query failed:', directSqlError); 265 + } else if (directSqlEntries && directSqlEntries.length > 0) { 266 + console.log('✅ Direct SQL query successful'); 267 + console.log(`Direct SQL query found entries with IDs: ${directSqlEntries.slice(0, 5).map(e => e.id).join(', ')}...`); 268 + entries = directSqlEntries; 264 269 } 265 270 266 - if (idSortedEntries && idSortedEntries.length > 0) { 267 - console.log('✅ ID-sorted query successful'); 268 - console.log(`ID-sorted query found entries with IDs: ${idSortedEntries.slice(0, 5).map(e => e.id).join(', ')}...`); 269 - entries = idSortedEntries; 271 + // If we already have results, no need to try other approaches 272 + if (entries && entries.length > 0) { 273 + console.log('Using entries from direct SQL query'); 270 274 } else { 271 - console.warn('⚠️ ID-sorted query returned no entries'); 275 + // Regular approach: Get entries with highest IDs 276 + const { data: idSortedEntries, error: idSortError } = await supabase 277 + .from('flushing_records') 278 + .select('*') 279 + .order('id', { ascending: false }) 280 + .limit(MAX_ENTRIES); 281 + 282 + if (idSortError) { 283 + throw idSortError; 284 + } 285 + 286 + if (idSortedEntries && idSortedEntries.length > 0) { 287 + console.log('✅ ID-sorted query successful'); 288 + console.log(`ID-sorted query found entries with IDs: ${idSortedEntries.slice(0, 5).map(e => e.id).join(', ')}...`); 289 + entries = idSortedEntries; 290 + } else { 291 + console.warn('⚠️ ID-sorted query returned no entries'); 292 + } 272 293 } 273 294 } catch (err) { 274 - console.error('❌ Error with ID-sorted query:', err); 295 + console.error('❌ Error with queries:', err); 275 296 } 276 297 277 298 // If first query failed, try a different approach
+32 -8
app/src/app/page.tsx
··· 199 199 setLoading(true); 200 200 setError(null); 201 201 202 - // Call our API endpoint to get the latest entries 202 + // Add a timestamp to the URL to ensure we bypass any caching 203 + const timestamp = Date.now(); 203 204 const url = forceRefresh 204 - ? '/api/bluesky/feed?refresh=true' 205 - : '/api/bluesky/feed'; 205 + ? `/api/bluesky/feed?refresh=true&_t=${timestamp}` 206 + : `/api/bluesky/feed?_t=${timestamp}`; 206 207 207 208 console.log(`Fetching feed from ${url} at ${new Date().toISOString()}`); 208 209 209 210 const response = await fetch(url, { 211 + method: 'GET', 210 212 cache: 'no-store', 211 213 headers: { 212 - 'Cache-Control': 'no-cache', 213 - 'Pragma': 'no-cache' 214 + 'Cache-Control': 'no-cache, no-store, must-revalidate', 215 + 'Pragma': 'no-cache', 216 + 'Expires': '0' 214 217 } 215 218 }); 216 219 ··· 462 465 // Request with a unique timestamp to completely bypass any caching 463 466 const timestamp = Date.now(); 464 467 const url = `/api/bluesky/feed?refresh=true&_t=${timestamp}`; 465 - console.log(`MANUAL REFRESH @ ${new Date().toISOString()}`); 468 + console.log(`🔄 MANUAL REFRESH @ ${new Date().toISOString()}`); 466 469 console.log(`Using URL: ${url}`); 467 470 471 + // Use strong no-cache headers to ensure browsers don't use cached responses 468 472 const response = await fetch(url, { 469 473 method: 'GET', 470 474 cache: 'no-store', 471 475 headers: { 472 476 'Cache-Control': 'no-cache, no-store, must-revalidate', 473 477 'Pragma': 'no-cache', 474 - 'Expires': '0' 478 + 'Expires': '0', 479 + 'X-Force-Fresh-Data': 'true' // Custom header to signal intent 475 480 } 476 481 }); 477 482 478 483 if (!response.ok) { 484 + console.error(`API error: ${response.status}, ${response.statusText}`); 479 485 throw new Error(`API error: ${response.status}`); 480 486 } 481 487 488 + // Attempt to extract response headers for debugging 489 + console.log('Response headers:', Object.fromEntries(response.headers.entries())); 490 + 482 491 const data = await response.json(); 483 492 console.log(`Refresh received ${data.entries?.length || 0} entries`); 484 493 485 494 if (data.entries && data.entries.length > 0) { 486 - console.log(`Highest ID from refresh: ${data.entries[0].id}`); 495 + console.log(`🔍 Highest ID from refresh: ${data.entries[0].id}`); 487 496 for (let i = 0; i < Math.min(5, data.entries.length); i++) { 488 497 console.log(` ${i+1}. ID: ${data.entries[i].id}, Handle: @${data.entries[i].authorHandle}, Text: "${data.entries[i].text.substring(0, 20)}..."`); 498 + } 499 + 500 + // Compare with current entries 501 + if (entries.length > 0) { 502 + const currentHighestId = entries[0].id; 503 + const newHighestId = data.entries[0].id; 504 + console.log(`📊 Comparison - Current highest ID: ${currentHighestId}, New highest ID: ${newHighestId}`); 505 + 506 + if (newHighestId > currentHighestId) { 507 + console.log('✅ Refresh successful! New entries are more recent.'); 508 + } else if (newHighestId === currentHighestId) { 509 + console.log('⚠️ Refresh returned same highest ID - no newer entries available.'); 510 + } else { 511 + console.warn('❌ WARNING: New entries have lower IDs than existing ones!'); 512 + } 489 513 } 490 514 } else { 491 515 console.log('No entries returned from refresh');