debug: implement surgical tracking and refined ID safety net for event files
- Added surgical console logging in '_refresh_file_li_background' to track raw API data vs processed records. - Refined the ID safety net to only inject missing keys, preventing accidental overwrites of existing relationships. - Hardened '_process_generic_props' to prevent 'null' random IDs from clobbering clean V3 IDs. - Restored specific object ID fields to 'properties_to_save' for full IndexedDB synchronization.
This commit is contained in:
@@ -142,7 +142,7 @@ export async function load_ae_obj_li__event_file({
|
|||||||
offset,
|
offset,
|
||||||
order_by_li,
|
order_by_li,
|
||||||
try_cache,
|
try_cache,
|
||||||
log_lvl: 0
|
log_lvl: 2
|
||||||
});
|
});
|
||||||
return cached_li;
|
return cached_li;
|
||||||
}
|
}
|
||||||
@@ -179,8 +179,9 @@ async function _refresh_file_li_background({
|
|||||||
}: any) {
|
}: any) {
|
||||||
if (typeof navigator !== 'undefined' && !navigator.onLine) return [];
|
if (typeof navigator !== 'undefined' && !navigator.onLine) return [];
|
||||||
try {
|
try {
|
||||||
// Force log_lvl to 1 for debugging
|
if (log_lvl) {
|
||||||
const internal_log_lvl = 1;
|
console.log(`📡 [DEBUG] _refresh_file_li_background: Fetching files for ${for_obj_type}:${for_obj_id}`);
|
||||||
|
}
|
||||||
|
|
||||||
const result_li = await api.get_ae_obj_li_v3({
|
const result_li = await api.get_ae_obj_li_v3({
|
||||||
api_cfg,
|
api_cfg,
|
||||||
@@ -193,14 +194,15 @@ async function _refresh_file_li_background({
|
|||||||
limit,
|
limit,
|
||||||
offset,
|
offset,
|
||||||
order_by_li,
|
order_by_li,
|
||||||
log_lvl: internal_log_lvl
|
log_lvl: log_lvl
|
||||||
});
|
});
|
||||||
|
|
||||||
if (result_li) {
|
if (result_li) {
|
||||||
if (internal_log_lvl) {
|
if (log_lvl) {
|
||||||
console.log(`[DEBUG] Raw API results for ${for_obj_type}:${for_obj_id}:`, result_li.length);
|
console.log(`📦 [DEBUG] Raw API results count:`, result_li.length);
|
||||||
if (result_li.length > 0) {
|
if (result_li.length > 0) {
|
||||||
console.log(`[DEBUG] First result sample:`, {
|
console.log(`🔍 [DEBUG] Sample Raw IDs:`, {
|
||||||
|
id: result_li[0].id,
|
||||||
event_file_id: result_li[0].event_file_id,
|
event_file_id: result_li[0].event_file_id,
|
||||||
event_id: result_li[0].event_id,
|
event_id: result_li[0].event_id,
|
||||||
for_id: result_li[0].for_id,
|
for_id: result_li[0].for_id,
|
||||||
@@ -209,58 +211,52 @@ async function _refresh_file_li_background({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SAFETY NET: If API returns null IDs, inject the ones we used for the query
|
// Minimal Fix: Only set what we are absolutely sure of if missing
|
||||||
const fixed_li = result_li.map((obj: any) => {
|
const fixed_li = result_li.map((obj: any) => {
|
||||||
const fixed_obj = { ...obj };
|
const fixed_obj = { ...obj };
|
||||||
|
if (!fixed_obj.for_type) fixed_obj.for_type = for_obj_type;
|
||||||
// IMPORTANT: In Aether, every event_file should have an event_id.
|
if (!fixed_obj.for_id) fixed_obj.for_id = for_obj_id;
|
||||||
// If it's missing, and we know it from stores or params, we should set it.
|
|
||||||
// For now, we prioritize fixing for_id and for_type which the loader definitely knows.
|
// Map specific ID field (e.g. event_presenter_id) ONLY if it matches the current for_obj_type
|
||||||
|
|
||||||
if (!fixed_obj.for_type || fixed_obj.for_type === null) fixed_obj.for_type = for_obj_type;
|
|
||||||
if (!fixed_obj.for_id || fixed_obj.for_id === null) fixed_obj.for_id = for_obj_id;
|
|
||||||
|
|
||||||
// Also ensure the specific ID field is populated (e.g. event_presenter_id)
|
|
||||||
const specific_id_key = `${for_obj_type}_id`;
|
const specific_id_key = `${for_obj_type}_id`;
|
||||||
if (!fixed_obj[specific_id_key] || fixed_obj[specific_id_key] === null) {
|
if (!fixed_obj[specific_id_key]) {
|
||||||
fixed_obj[specific_id_key] = for_obj_id;
|
fixed_obj[specific_id_key] = for_obj_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
return fixed_obj;
|
return fixed_obj;
|
||||||
});
|
});
|
||||||
|
|
||||||
const processed = await process_ae_obj__event_file_props({
|
const processed = await process_ae_obj__event_file_props({
|
||||||
obj_li: fixed_li,
|
obj_li: fixed_li,
|
||||||
log_lvl: internal_log_lvl
|
log_lvl
|
||||||
});
|
});
|
||||||
|
|
||||||
if (internal_log_lvl && processed.length > 0) {
|
if (log_lvl && processed.length > 0) {
|
||||||
console.log(`[DEBUG] Processed result sample:`, {
|
console.log(`🛠️ [DEBUG] Sample Processed Record:`, {
|
||||||
event_file_id: processed[0].event_file_id,
|
id: processed[0].id,
|
||||||
event_id: processed[0].event_id,
|
event_id: processed[0].event_id,
|
||||||
for_id: processed[0].for_id,
|
for_id: processed[0].for_id,
|
||||||
specific_id: (processed[0] as any)[`${for_obj_type}_id`]
|
event_presenter_id: processed[0].event_presenter_id
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (try_cache) {
|
if (try_cache) {
|
||||||
|
if (log_lvl) console.log(`💾 [DEBUG] Saving ${processed.length} records to ae_events_db.file`);
|
||||||
await db_save_ae_obj_li__ae_obj({
|
await db_save_ae_obj_li__ae_obj({
|
||||||
db_instance: db_events,
|
db_instance: db_events,
|
||||||
table_name: 'file',
|
table_name: 'file',
|
||||||
obj_li: processed,
|
obj_li: processed,
|
||||||
properties_to_save,
|
properties_to_save,
|
||||||
log_lvl: internal_log_lvl
|
log_lvl
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return processed;
|
return processed;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`[DEBUG] Error in _refresh_file_li_background:`, e);
|
if (log_lvl) console.error(`❌ [DEBUG] Error in _refresh_file_li_background:`, e);
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
}
|
}export async function create_event_file_obj_from_hosted_file_async({
|
||||||
|
|
||||||
export async function create_event_file_obj_from_hosted_file_async({
|
|
||||||
api_cfg,
|
api_cfg,
|
||||||
hosted_file_id,
|
hosted_file_id,
|
||||||
params = {},
|
params = {},
|
||||||
|
|||||||
Reference in New Issue
Block a user