mirror of
https://github.com/christianvidalwolf-prog/Craze-Data-check.git
synced 2026-08-03 15:35:23 +02:00
restore cpnp values from history
This commit is contained in:
+21
-8
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user