diff --git a/src/App.tsx b/src/App.tsx index 8dd7c36..22d0b57 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -134,9 +134,6 @@ export default function App() { console.log('Fetching synced data from Supabase...'); const syncedData = await getAllSyncedRows(); - // TEMP DIAG - const d = syncedData['51016DE']; - console.log('[DIAG v2] 51016DE:', d ? `status=${d.status} len=${d.data?.length} [103]=${JSON.stringify(d.data?.[103])}` : 'NOT FOUND'); // Extend headers with virtual columns if the Excel is shorter than the saved data. // COLUMNS hardcoded indices (PRODUCT_TYPE=103, ITEM_TO_LOGISTIC=104, etc.) are used diff --git a/src/lib/supabase.ts b/src/lib/supabase.ts index ef37ec0..8bf2c15 100644 --- a/src/lib/supabase.ts +++ b/src/lib/supabase.ts @@ -41,26 +41,35 @@ export interface SyncedRow { } export async function getAllSyncedRows(): Promise> { + const PAGE_SIZE = 1000; + const result: Record = {}; try { - const response = await safeFetch( - `${SUPABASE_URL}/rest/v1/products?select=product_id,data,status&order=updated_at.desc&limit=1000`, - { cache: 'no-store' } - ); + let offset = 0; + // Paginate until Supabase returns fewer rows than PAGE_SIZE (no more pages). + // Supabase REST caps a single response at 1000 rows, so we must page. + // Safety cap at 20 pages (20k products) to avoid infinite loops. + for (let page = 0; page < 20; page++) { + const response = await safeFetch( + `${SUPABASE_URL}/rest/v1/products?select=product_id,data,status&order=product_id.asc&limit=${PAGE_SIZE}&offset=${offset}`, + { cache: 'no-store' } + ); - if (!response.ok) { - const errText = await response.text(); - console.error('getAllSyncedRows failed:', response.status, errText); - return {}; - } - const rows = await response.json(); - const result: Record = {}; - for (const row of rows) { - result[row.product_id] = { data: row.data, status: row.status }; + if (!response.ok) { + const errText = await response.text(); + console.error('getAllSyncedRows failed:', response.status, errText); + return result; + } + const rows = await response.json(); + for (const row of rows) { + result[row.product_id] = { data: row.data, status: row.status }; + } + if (rows.length < PAGE_SIZE) break; + offset += PAGE_SIZE; } return result; } catch (error) { console.error('Error fetching synced rows from Supabase:', error); - return {}; + return result; } }