fix(storage): enforce Ads cached schema invalidation to clear broken numeric mapped columns

This commit is contained in:
Christian Vidal Wolf
2026-02-26 10:47:36 +01:00
parent fa588a6444
commit adda0cd58f
2 changed files with 27 additions and 3 deletions
+15 -1
View File
@@ -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