mirror of
https://github.com/christianvidalwolf-prog/CrazeAnalytix.git
synced 2026-08-03 15:05:22 +02:00
fix(storage): enforce Ads cached schema invalidation to clear broken numeric mapped columns
This commit is contained in:
@@ -87,12 +87,22 @@ function aggregateWeeklyMetrics(
|
||||
w.revenue += r.salesTotal || (r as any).sellOut || 0;
|
||||
w.adRevenue += r.salesAds || 0;
|
||||
w.sessions += r.glanceViews || 0;
|
||||
w.cost += r.cost || 0;
|
||||
w.cost += Number(r.cost) || 0;
|
||||
w.clicks += r.clicks || 0;
|
||||
w.impressions += r.impressions || 0;
|
||||
}
|
||||
|
||||
return Array.from(weeklyMap.values())
|
||||
// Debug ad map
|
||||
console.log(`[aggregateWeeklyMetrics] ASIN match for ${marketplace}:`, asinSet);
|
||||
const debugArr = Array.from(weeklyMap.values());
|
||||
const hasAds = debugArr.some(w => w.cost > 0 || w.adRevenue > 0);
|
||||
if (!hasAds) {
|
||||
console.log(`[aggregateWeeklyMetrics WARNING] 0 ad data grouped for mkt ${marketplace}!`, debugArr);
|
||||
} else {
|
||||
console.log(`[aggregateWeeklyMetrics SUCCESS] Found ad usage:`, debugArr.filter(w => w.cost > 0));
|
||||
}
|
||||
|
||||
return debugArr
|
||||
.sort((a, b) => a.timestamp - b.timestamp)
|
||||
.map(w => ({
|
||||
...w,
|
||||
|
||||
+15
-1
@@ -7,7 +7,7 @@ const ADS_STORE_NAME = 'adsData';
|
||||
const DB_VERSION = 2;
|
||||
// Increment this when data processing logic changes (e.g., field mapping changes)
|
||||
// This forces cache invalidation and re-processing of CSV data
|
||||
const DATA_SCHEMA_VERSION = 2; // Updated for LICENSE column mapping
|
||||
const DATA_SCHEMA_VERSION = 3; // Updated to clear broken Ads data
|
||||
|
||||
const initDB = (): Promise<IDBDatabase> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -115,6 +115,7 @@ export const saveAdsData = async (data: any[]): Promise<void> => {
|
||||
|
||||
store.put(data, 'currentData');
|
||||
store.put(new Date().toISOString(), 'lastUpdated');
|
||||
store.put(DATA_SCHEMA_VERSION, 'schemaVersion');
|
||||
|
||||
transaction.oncomplete = () => resolve();
|
||||
transaction.onerror = () => reject(transaction.error);
|
||||
@@ -133,8 +134,21 @@ export const loadAdsData = async (): Promise<{ data: any[]; lastUpdated: string
|
||||
|
||||
const dataReq = store.get('currentData');
|
||||
const dateReq = store.get('lastUpdated');
|
||||
const versionReq = store.get('schemaVersion');
|
||||
|
||||
transaction.oncomplete = () => {
|
||||
const cachedVersion = versionReq.result;
|
||||
|
||||
// If schema version doesn't match, invalidate cache
|
||||
if (cachedVersion !== DATA_SCHEMA_VERSION) {
|
||||
console.log('[Storage] Ads Schema version mismatch. Cached:', cachedVersion, 'Current:', DATA_SCHEMA_VERSION);
|
||||
resolve({
|
||||
data: [],
|
||||
lastUpdated: null
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
resolve({
|
||||
data: dataReq.result || [],
|
||||
lastUpdated: dateReq.result || null
|
||||
|
||||
Reference in New Issue
Block a user