fix(events): Fix pres mgmt reports data loading and field mapping

- Fix session detail page params not being passed to component (causing undefined session_id)
- Fix wrapper components discarding API enriched data by re-fetching from IDB
- Fix event_file, event_session, event_presenter wrappers to preserve API data
- Add optional chaining for hash_sha256 field to prevent undefined crashes
- Fix search__event_file to always process API results before returning
- Ensures hosted_file_size -> file_size field mapping for reports
- All pres mgmt reports (files, sessions, presenters) now work on cold-start
This commit is contained in:
Scott Idem
2026-02-26 14:36:46 -05:00
parent 61025ea0d5
commit 9547da6da6
6 changed files with 72 additions and 84 deletions

View File

@@ -440,20 +440,29 @@ export async function search__event_file({
params: { inc_hosted_file },
log_lvl
});
if (result_li && try_cache) {
// CRITICAL: Always process the results to map hosted_file_size → file_size
// and other field mappings for UI consistency
if (result_li) {
const processed = await process_ae_obj__event_file_props({
obj_li: result_li,
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'file',
obj_li: processed,
properties_to_save,
log_lvl
});
if (try_cache) {
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'file',
obj_li: processed,
properties_to_save,
log_lvl
});
}
return processed; // Return processed data with mapped fields
}
return result_li || [];
return [];
}
export const qry__event_file = search__event_file;

View File

@@ -54,44 +54,32 @@
let dq__where_eq_id_val = $derived(link_to_id ?? '');
// *** Functions and Logic
// OPTIMIZATION: If event_presenter_obj_li is provided (from API/reports),
// use it directly instead of fetching from IDB. The API returns fully
// enriched data with all joined fields (session names, presentation names, etc.)
// that aren't available in the base IDB presenter table.
let lq__event_presenter_obj_li = $derived(
liveQuery(async () => {
let results: any;
// let event_presenter_id_random_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
// for (let i = 0; i < $events_sess?.event_presenter_obj_li.length; i++) {
// let event_presenter_obj = $events_sess?.event_presenter_obj_li[i];
// let event_presenter_id_random = event_presenter_obj.event_presenter_id_random;
// event_presenter_id_random_li.push(event_presenter_id_random);
// }
// If data is already provided (from API reports with joins), use it directly
if (event_presenter_obj_li?.length) {
if (log_lvl) {
console.log(
`LQ - Using event_presenter_obj_li to get event presenters.`
`LQ - Using provided event_presenter_obj_li (${event_presenter_obj_li.length} presenters with API joins)`
);
}
return event_presenter_obj_li;
}
event_presenter_id_random_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
for (let i = 0; i < event_presenter_obj_li.length; i++) {
let event_presenter_obj = event_presenter_obj_li[i];
let event_presenter_id_random =
event_presenter_obj.event_presenter_id_random;
event_presenter_id_random_li.push(
event_presenter_id_random
// Otherwise fetch from IDB for link_to_type/link_to_id lookups
if (link_to_type && link_to_id) {
if (log_lvl) {
console.log(
`LQ - Fetching from IDB where: ${dq__where_type_id_val} = ${dq__where_eq_id_val}`
);
}
// if (event_presenter_id_random_li.length) {
results = await db_events.presenter.bulkGet(
event_presenter_id_random_li
);
// }
} else if (link_to_type && link_to_id) {
console.log(
`Trying where: ${dq__where_type_id_val}; equals: ${dq__where_eq_id_val}`
);
event_presenter_id_random_li = [];
results = await db_events.presenter
.where(dq__where_type_id_val)

View File

@@ -51,9 +51,13 @@ export async function load({ params, parent }) {
// WARNING: Precaution against shared data between sites and presentations.
data[account_id] = ae_acct;
// Pass the pre-loaded data to the page component
data.initial_session_obj = initial_session_obj;
// CRITICAL: SvelteKit does NOT automatically include params in returned data.
// The page component needs these for liveQuery subscriptions.
data.params = params;
return data;
}

View File

@@ -117,11 +117,11 @@
);
csv_row.push(ae_obj_li[i].extension ? ae_obj_li[i].extension : '');
csv_row.push(
ae_obj_li[i].file_size
? ae_util.format_bytes(ae_obj_li[i].file_size)
ae_obj_li[i].file_size || ae_obj_li[i].hosted_file_size
? ae_util.format_bytes(ae_obj_li[i].file_size || ae_obj_li[i].hosted_file_size)
: ''
);
csv_row.push(ae_obj_li[i].hash_sha256.slice(0, 10) + '...');
csv_row.push(ae_obj_li[i].hash_sha256?.slice(0, 10) ?? 'N/A');
csv_row.push(
ae_obj_li[i].created_on
? ae_util.iso_datetime_formatter(
@@ -455,7 +455,7 @@
event_file_obj?.filename
)}&key={$ae_api.account_id}"
class="btn btn-sm p-1 preset-tonal-secondary *:hover:inline lg:text-xs underline"
title={`Download this file:\n${ae_util.clean_filename(event_file_obj?.filename)}\n[API] SHA256: ${event_file_obj?.hash_sha256.slice(0, 10)}...\nHosted ID: ${event_file_obj?.hosted_file_id} Event File ID: ${event_file_obj?.event_file_id}`}
title={`Download this file:\n${ae_util.clean_filename(event_file_obj?.filename)}\n[API] SHA256: ${event_file_obj?.hash_sha256?.slice(0, 10) ?? 'N/A'}\nHosted ID: ${event_file_obj?.hosted_file_id} Event File ID: ${event_file_obj?.event_file_id}`}
>
<span class="fas fa-download mx-1"
></span>
@@ -549,7 +549,7 @@
</td>
<td class="px-4 py-2"
>{ae_util.format_bytes(
event_file_obj?.file_size
event_file_obj?.file_size || event_file_obj?.hosted_file_size
)}</td
>
<td class="px-4 py-2">

View File

@@ -61,47 +61,37 @@
let dq__where_eq_id_val = $derived(link_to_id ?? '');
// *** Functions and Logic
// OPTIMIZATION: If event_file_obj_li is provided (from API/reports),
// use it directly instead of fetching from IDB. The API returns fully
// enriched data with all joined fields (session names, presentation names, etc.)
// that aren't available in the base IDB file table.
let lq__event_file_obj_li = $derived(
liveQuery(async () => {
let results: any;
// let event_file_id_random_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
// for (let i = 0; i < $events_sess?.event_file_obj_li.length; i++) {
// let event_file_obj = $events_sess?.event_file_obj_li[i];
// let event_file_id_random = event_file_obj.event_file_id_random;
// event_file_id_random_li.push(event_file_id_random);
// }
// If data is already provided (from API reports with joins), use it directly
if (event_file_obj_li?.length) {
if (log_lvl) {
console.log(
`LQ - Using event_file_obj_li to get event files.`
`LQ - Using provided event_file_obj_li (${event_file_obj_li.length} files with API joins)`
);
}
return event_file_obj_li;
}
event_file_id_random_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
for (let i = 0; i < event_file_obj_li.length; i++) {
let event_file_obj = event_file_obj_li[i];
let event_file_id_random =
event_file_obj.event_file_id_random;
event_file_id_random_li.push(event_file_id_random);
// Otherwise fetch from IDB for link_to_type/link_to_id lookups
if (link_to_type && link_to_id) {
if (log_lvl) {
console.log(
`LQ - Fetching from IDB where: ${dq__where_type_id_val} = ${dq__where_eq_id_val}`
);
}
// if (event_file_id_random_li.length) {
results = await db_events.file.bulkGet(event_file_id_random_li);
// }
} else if (link_to_type && link_to_id) {
console.log(
`Trying where: ${dq__where_type_id_val}; equals: ${dq__where_eq_id_val}`
);
event_file_id_random_li = [];
results = await db_events.file
.where(dq__where_type_id_val)
.equals(dq__where_eq_id_val)
.sortBy('name');
} else {
event_file_id_random_li = [];
results = [];
}

View File

@@ -53,35 +53,32 @@
let dq__where_eq_id_val = $derived(link_to_id);
// *** Functions and Logic
// OPTIMIZATION: If event_session_obj_li is provided (from API/reports),
// use it directly instead of fetching from IDB. The API returns fully
// enriched data with all joined fields (location names, file counts, etc.)
// that aren't available in the base IDB session table.
let lq__event_session_obj_li = $derived(
liveQuery(async () => {
let results: any;
// If data is already provided (from API reports with joins), use it directly
if (event_session_obj_li?.length) {
if (log_lvl) {
console.log(
`LQ - Using event_session_obj_li to get event sessions.`
`LQ - Using provided event_session_obj_li (${event_session_obj_li.length} sessions with API joins)`
);
}
return event_session_obj_li;
}
event_session_id_random_li = []; // This is to prevent the array from constantly updating and triggering the liveQuery.
for (let i = 0; i < event_session_obj_li.length; i++) {
let event_session_obj = event_session_obj_li[i];
let event_session_id_random =
event_session_obj.event_session_id_random;
event_session_id_random_li.push(event_session_id_random);
// Otherwise fetch from IDB for link_to_type/link_to_id lookups
if (link_to_type && link_to_id) {
if (log_lvl) {
console.log(
`LQ - Fetching from IDB where: ${dq__where_type_id_val} = ${dq__where_eq_id_val}`
);
}
// if (event_session_id_random_li.length) {
results = await db_events.session.bulkGet(
event_session_id_random_li
);
// }
} else if (link_to_type && link_to_id) {
console.log(
`Trying where: ${dq__where_type_id_val}; equals: ${dq__where_eq_id_val}`
);
event_session_id_random_li = [];
results = await db_events.session
.where(dq__where_type_id_val)