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,
|
||||
order_by_li,
|
||||
try_cache,
|
||||
log_lvl: 0
|
||||
log_lvl: 2
|
||||
});
|
||||
return cached_li;
|
||||
}
|
||||
@@ -179,8 +179,9 @@ async function _refresh_file_li_background({
|
||||
}: any) {
|
||||
if (typeof navigator !== 'undefined' && !navigator.onLine) return [];
|
||||
try {
|
||||
// Force log_lvl to 1 for debugging
|
||||
const internal_log_lvl = 1;
|
||||
if (log_lvl) {
|
||||
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({
|
||||
api_cfg,
|
||||
@@ -193,14 +194,15 @@ async function _refresh_file_li_background({
|
||||
limit,
|
||||
offset,
|
||||
order_by_li,
|
||||
log_lvl: internal_log_lvl
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
|
||||
if (result_li) {
|
||||
if (internal_log_lvl) {
|
||||
console.log(`[DEBUG] Raw API results for ${for_obj_type}:${for_obj_id}:`, result_li.length);
|
||||
if (log_lvl) {
|
||||
console.log(`📦 [DEBUG] Raw API results count:`, result_li.length);
|
||||
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_id: result_li[0].event_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_obj = { ...obj };
|
||||
|
||||
// IMPORTANT: In Aether, every event_file should have an event_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.
|
||||
|
||||
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)
|
||||
if (!fixed_obj.for_type) fixed_obj.for_type = for_obj_type;
|
||||
if (!fixed_obj.for_id) fixed_obj.for_id = for_obj_id;
|
||||
|
||||
// Map specific ID field (e.g. event_presenter_id) ONLY if it matches the current for_obj_type
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
return fixed_obj;
|
||||
});
|
||||
|
||||
const processed = await process_ae_obj__event_file_props({
|
||||
obj_li: fixed_li,
|
||||
log_lvl: internal_log_lvl
|
||||
log_lvl
|
||||
});
|
||||
|
||||
if (internal_log_lvl && processed.length > 0) {
|
||||
console.log(`[DEBUG] Processed result sample:`, {
|
||||
event_file_id: processed[0].event_file_id,
|
||||
if (log_lvl && processed.length > 0) {
|
||||
console.log(`🛠️ [DEBUG] Sample Processed Record:`, {
|
||||
id: processed[0].id,
|
||||
event_id: processed[0].event_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 (log_lvl) console.log(`💾 [DEBUG] Saving ${processed.length} records to ae_events_db.file`);
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_events,
|
||||
table_name: 'file',
|
||||
obj_li: processed,
|
||||
properties_to_save,
|
||||
log_lvl: internal_log_lvl
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
return processed;
|
||||
}
|
||||
} 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 [];
|
||||
}
|
||||
|
||||
export async function create_event_file_obj_from_hosted_file_async({
|
||||
}export async function create_event_file_obj_from_hosted_file_async({
|
||||
api_cfg,
|
||||
hosted_file_id,
|
||||
params = {},
|
||||
|
||||
Reference in New Issue
Block a user