Forráskód Böngészése

Refactor: Adjust article fetching limits

gpt-engineer-app[bot] 2 hónapja
szülő
commit
3f1ea1071f
2 módosított fájl, 15 hozzáadás és 11 törlés
  1. 8 4
      src/hooks/useFeedArticles.tsx
  2. 7 7
      src/hooks/useRealArticles.tsx

+ 8 - 4
src/hooks/useFeedArticles.tsx

@@ -4,7 +4,8 @@ import { useAuth } from './useAuth';
 import { NewsItem } from '@/types/news';
 import { toast } from 'sonner';
 
-const ARTICLES_PER_PAGE = 20;
+const ARTICLES_PER_PAGE = 100;
+const FETCH_LIMIT = 200;
 
 interface FeedInfo {
   name: string;
@@ -52,7 +53,10 @@ export function useFeedArticles(feedId: string, page: number = 1) {
       const from = (page - 1) * ARTICLES_PER_PAGE;
       const to = from + ARTICLES_PER_PAGE - 1;
 
-      // Fetch articles with pagination
+      // Fetch articles with pagination - fetch more than displayed
+      const fetchFrom = (page - 1) * FETCH_LIMIT;
+      const fetchTo = fetchFrom + FETCH_LIMIT - 1;
+      
       let query = supabase
         .from('articles')
         .select(`
@@ -62,7 +66,7 @@ export function useFeedArticles(feedId: string, page: number = 1) {
         `)
         .eq('feed_id', feedId)
         .order('published_at', { ascending: false })
-        .range(from, to);
+        .range(fetchFrom, fetchTo);
 
       const { data: articlesData, error: articlesError } = await query;
 
@@ -92,7 +96,7 @@ export function useFeedArticles(feedId: string, page: number = 1) {
           feedId: article.feed_id
         })) || [];
 
-      setArticles(transformedArticles);
+      setArticles(transformedArticles.slice(0, ARTICLES_PER_PAGE));
     } catch (error) {
       console.error('💥 Error in fetchFeedArticles:', error);
       toast.error('Erreur lors du chargement des articles');

+ 7 - 7
src/hooks/useRealArticles.tsx

@@ -72,7 +72,7 @@ export function useRealArticles(dateFilter?: 'today' | 'yesterday' | null, showF
 
         const { data: pinnedArticles, error: pinnedError } = await pinnedQuery
           .order('published_at', { ascending: false })
-          .limit(50);
+          .limit(100);
 
         if (pinnedError) {
           console.error('❌ Error fetching pinned articles:', pinnedError);
@@ -111,7 +111,7 @@ export function useRealArticles(dateFilter?: 'today' | 'yesterday' | null, showF
         
         const { data: regularArticles, error: regularError } = await regularQuery
           .order('published_at', { ascending: false })
-          .limit(100);
+          .limit(200);
 
         if (regularError) {
           console.error('❌ Error fetching regular articles:', regularError);
@@ -151,7 +151,7 @@ export function useRealArticles(dateFilter?: 'today' | 'yesterday' | null, showF
             feedId: article.feed_id
           })) || [];
 
-        setArticles(transformedArticles);
+        setArticles(transformedArticles.slice(0, 100));
       } else {
         // For users wanting all articles or visitors - show all articles from all feeds
         console.log('👤 Loading all articles (visitor or showFollowedOnly=false)');
@@ -173,7 +173,7 @@ export function useRealArticles(dateFilter?: 'today' | 'yesterday' | null, showF
 
           const { data: pinnedData, error: pinnedError } = await pinnedQuery
             .order('published_at', { ascending: false })
-            .limit(50);
+            .limit(100);
 
           if (pinnedError) {
             console.error('❌ Error fetching pinned articles:', pinnedError);
@@ -195,7 +195,7 @@ export function useRealArticles(dateFilter?: 'today' | 'yesterday' | null, showF
         
         const { data: regularData, error: regularError } = await regularQuery
           .order('published_at', { ascending: false })
-          .limit(100);
+          .limit(200);
 
         if (regularError) {
           console.error('❌ Error fetching regular articles:', regularError);
@@ -272,10 +272,10 @@ export function useRealArticles(dateFilter?: 'today' | 'yesterday' | null, showF
             title: transformedArticles[0].title.substring(0, 50),
             isRead: transformedArticles[0].isRead,
             isPinned: transformedArticles[0].isPinned
-          } : null
+           } : null
         });
 
-        setArticles(transformedArticles);
+        setArticles(transformedArticles.slice(0, 100));
       }
     } catch (error) {
       console.error('💥 Error in fetchArticles:', error);