restore cpnp values from history

This commit is contained in:
Christian Vidal Wolf
2026-05-20 14:56:55 +02:00
parent d17db2761b
commit cb913b9d72
2 changed files with 22 additions and 8 deletions
+21 -8
View File
@@ -279,16 +279,29 @@ export async function getHistory(): Promise<HistoryEntry[]> {
export async function getHistoryDataForMerge(): Promise<Record<string, ExcelRow>> {
try {
const response = await safeFetch(
`${SUPABASE_URL}/rest/v1/products_history?select=product_id,old_data,new_data,changed_at,id`,
{ cache: 'no-store' }
);
const PAGE_SIZE = 1000;
const entries: HistoryEntry[] = [];
if (!response.ok) {
console.error('[getHistoryDataForMerge] Error:', response.status);
return {};
for (let page = 0; page < 20; page++) {
const offset = page * PAGE_SIZE;
const response = await safeFetch(
`${SUPABASE_URL}/rest/v1/products_history?select=product_id,old_data,new_data,changed_at,id&order=changed_at.asc&limit=${PAGE_SIZE}&offset=${offset}`,
{ cache: 'no-store' }
);
if (!response.ok) {
console.error('[getHistoryDataForMerge] Error:', response.status);
return {};
}
const batch: HistoryEntry[] = await response.json();
entries.push(
...batch.filter((entry: HistoryEntry) => entry.product_id !== CONTROL_DASHBOARD_SNAPSHOT_PRODUCT_ID)
);
if (batch.length < PAGE_SIZE) break;
}
const entries: HistoryEntry[] = (await response.json()).filter((entry: HistoryEntry) => entry.product_id !== CONTROL_DASHBOARD_SNAPSHOT_PRODUCT_ID);
entries.sort((a, b) => {
const timeDelta = new Date(a.changed_at).getTime() - new Date(b.changed_at).getTime();
if (timeDelta !== 0) return timeDelta;