···202202 }
203203 }
204204205205- // IMPORTANT: We're disabling the cache completely to ensure we always get fresh data
206206- // This is because we're having issues with stale data
207207- if (false && !forceRefresh && now - lastFetchTime < CACHE_TTL && cachedEntries.length > 0) {
205205+ // We're completely disabling server-side caching to ensure we always get fresh data
206206+ // This is because we've been having issues with stale data
207207+ // In a future update, we may re-enable caching with proper invalidation
208208+ if (false) { // This condition will never be true
208209 console.log('Returning cached entries');
209210 return NextResponse.json({ entries: cachedEntries });
210211 }
···223224 console.log(`Querying database for latest ${MAX_ENTRIES} entries at ${new Date().toISOString()}...`);
224225225226 // Debug log the SQL query we're about to execute
226226- console.log('SQL Query: SELECT id, uri, cid, did, text, emoji, created_at, handle FROM flushing_records ORDER BY created_at DESC LIMIT 20');
227227+ console.log('SQL Query: SELECT id, uri, cid, did, text, emoji, created_at, handle FROM flushing_records ORDER BY id DESC LIMIT 20');
227228228229 // First, let's check what's the highest ID in the database to debug
229230 const { data: maxIdResult } = await supabase
···252253 let entries;
253254254255 try {
255255- // First try: Get entries with highest IDs
256256- const { data: idSortedEntries, error: idSortError } = await supabase
256256+ // Direct SQL query to get the most recent entries by ID
257257+ const { data: directSqlEntries, error: directSqlError } = await supabase
257258 .from('flushing_records')
258259 .select('*')
259260 .order('id', { ascending: false })
260261 .limit(MAX_ENTRIES);
261261-262262- if (idSortError) {
263263- throw idSortError;
262262+263263+ if (directSqlError) {
264264+ console.error('❌ Direct SQL query failed:', directSqlError);
265265+ } else if (directSqlEntries && directSqlEntries.length > 0) {
266266+ console.log('✅ Direct SQL query successful');
267267+ console.log(`Direct SQL query found entries with IDs: ${directSqlEntries.slice(0, 5).map(e => e.id).join(', ')}...`);
268268+ entries = directSqlEntries;
264269 }
265270266266- if (idSortedEntries && idSortedEntries.length > 0) {
267267- console.log('✅ ID-sorted query successful');
268268- console.log(`ID-sorted query found entries with IDs: ${idSortedEntries.slice(0, 5).map(e => e.id).join(', ')}...`);
269269- entries = idSortedEntries;
271271+ // If we already have results, no need to try other approaches
272272+ if (entries && entries.length > 0) {
273273+ console.log('Using entries from direct SQL query');
270274 } else {
271271- console.warn('⚠️ ID-sorted query returned no entries');
275275+ // Regular approach: Get entries with highest IDs
276276+ const { data: idSortedEntries, error: idSortError } = await supabase
277277+ .from('flushing_records')
278278+ .select('*')
279279+ .order('id', { ascending: false })
280280+ .limit(MAX_ENTRIES);
281281+282282+ if (idSortError) {
283283+ throw idSortError;
284284+ }
285285+286286+ if (idSortedEntries && idSortedEntries.length > 0) {
287287+ console.log('✅ ID-sorted query successful');
288288+ console.log(`ID-sorted query found entries with IDs: ${idSortedEntries.slice(0, 5).map(e => e.id).join(', ')}...`);
289289+ entries = idSortedEntries;
290290+ } else {
291291+ console.warn('⚠️ ID-sorted query returned no entries');
292292+ }
272293 }
273294 } catch (err) {
274274- console.error('❌ Error with ID-sorted query:', err);
295295+ console.error('❌ Error with queries:', err);
275296 }
276297277298 // If first query failed, try a different approach
+32-8
app/src/app/page.tsx
···199199 setLoading(true);
200200 setError(null);
201201202202- // Call our API endpoint to get the latest entries
202202+ // Add a timestamp to the URL to ensure we bypass any caching
203203+ const timestamp = Date.now();
203204 const url = forceRefresh
204204- ? '/api/bluesky/feed?refresh=true'
205205- : '/api/bluesky/feed';
205205+ ? `/api/bluesky/feed?refresh=true&_t=${timestamp}`
206206+ : `/api/bluesky/feed?_t=${timestamp}`;
206207207208 console.log(`Fetching feed from ${url} at ${new Date().toISOString()}`);
208209209210 const response = await fetch(url, {
211211+ method: 'GET',
210212 cache: 'no-store',
211213 headers: {
212212- 'Cache-Control': 'no-cache',
213213- 'Pragma': 'no-cache'
214214+ 'Cache-Control': 'no-cache, no-store, must-revalidate',
215215+ 'Pragma': 'no-cache',
216216+ 'Expires': '0'
214217 }
215218 });
216219···462465 // Request with a unique timestamp to completely bypass any caching
463466 const timestamp = Date.now();
464467 const url = `/api/bluesky/feed?refresh=true&_t=${timestamp}`;
465465- console.log(`MANUAL REFRESH @ ${new Date().toISOString()}`);
468468+ console.log(`🔄 MANUAL REFRESH @ ${new Date().toISOString()}`);
466469 console.log(`Using URL: ${url}`);
467470471471+ // Use strong no-cache headers to ensure browsers don't use cached responses
468472 const response = await fetch(url, {
469473 method: 'GET',
470474 cache: 'no-store',
471475 headers: {
472476 'Cache-Control': 'no-cache, no-store, must-revalidate',
473477 'Pragma': 'no-cache',
474474- 'Expires': '0'
478478+ 'Expires': '0',
479479+ 'X-Force-Fresh-Data': 'true' // Custom header to signal intent
475480 }
476481 });
477482478483 if (!response.ok) {
484484+ console.error(`API error: ${response.status}, ${response.statusText}`);
479485 throw new Error(`API error: ${response.status}`);
480486 }
481487488488+ // Attempt to extract response headers for debugging
489489+ console.log('Response headers:', Object.fromEntries(response.headers.entries()));
490490+482491 const data = await response.json();
483492 console.log(`Refresh received ${data.entries?.length || 0} entries`);
484493485494 if (data.entries && data.entries.length > 0) {
486486- console.log(`Highest ID from refresh: ${data.entries[0].id}`);
495495+ console.log(`🔍 Highest ID from refresh: ${data.entries[0].id}`);
487496 for (let i = 0; i < Math.min(5, data.entries.length); i++) {
488497 console.log(` ${i+1}. ID: ${data.entries[i].id}, Handle: @${data.entries[i].authorHandle}, Text: "${data.entries[i].text.substring(0, 20)}..."`);
498498+ }
499499+500500+ // Compare with current entries
501501+ if (entries.length > 0) {
502502+ const currentHighestId = entries[0].id;
503503+ const newHighestId = data.entries[0].id;
504504+ console.log(`📊 Comparison - Current highest ID: ${currentHighestId}, New highest ID: ${newHighestId}`);
505505+506506+ if (newHighestId > currentHighestId) {
507507+ console.log('✅ Refresh successful! New entries are more recent.');
508508+ } else if (newHighestId === currentHighestId) {
509509+ console.log('⚠️ Refresh returned same highest ID - no newer entries available.');
510510+ } else {
511511+ console.warn('❌ WARNING: New entries have lower IDs than existing ones!');
512512+ }
489513 }
490514 } else {
491515 console.log('No entries returned from refresh');