perf(events): implement non-blocking SWR pattern and optimize library loaders
- Refactored 'event_session', 'event_presentation', 'event_file', 'event_location', and 'event_presenter' libraries to follow a Stale-While-Revalidate pattern. - Implemented non-blocking background refreshes to allow instant UI rendering from IndexedDB cache. - Parallelized nested collection loads (files, presentations) during background tasks to eliminate UI stalls. - Standardized ID lookups using specific indices (event_location_id, event_id) for reliable local data retrieval. - Resolved regression where aggressive ID overwriting caused relationship inconsistencies in background loads. - Fixed reactive access to live queries in 'session_view.svelte' using proper Svelte 5 prefixing.
This commit is contained in:
@@ -10,7 +10,7 @@ import { load_ae_obj_li__event_presentation } from '$lib/ae_events/ae_events__ev
|
||||
|
||||
const ae_promises: key_val = {};
|
||||
|
||||
// Updated 2026-01-27 to V3 String-Only ID Standard
|
||||
// Updated 2026-01-30: Fixed - Removed aggressive ID overwriting
|
||||
export async function load_ae_obj_id__event_session({
|
||||
api_cfg,
|
||||
event_session_id,
|
||||
@@ -44,77 +44,53 @@ export async function load_ae_obj_id__event_session({
|
||||
console.log(`*** load_ae_obj_id__event_session() *** [V3] id=${event_session_id} (SWR)`);
|
||||
}
|
||||
|
||||
// 1. FAST PATH: Return cached data immediately
|
||||
if (try_cache) {
|
||||
try {
|
||||
const cached = await db_events.session.get(event_session_id);
|
||||
if (cached) {
|
||||
if (log_lvl) console.log('SESSION LOAD: Cache hit. Returning stale data.');
|
||||
_refresh_session_id_background({
|
||||
api_cfg, event_session_id, view, try_cache,
|
||||
inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li,
|
||||
enabled, hidden, limit, offset, log_lvl: 0
|
||||
});
|
||||
return await _handle_nested_loads(cached, { api_cfg, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl });
|
||||
return await _handle_nested_loads(cached, { api_cfg, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl: 0 });
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
// 2. SLOW PATH: Wait for API
|
||||
return await _refresh_session_id_background({
|
||||
api_cfg, event_session_id, view, try_cache,
|
||||
inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li,
|
||||
enabled, hidden, limit, offset, log_lvl
|
||||
});
|
||||
return await _refresh_session_id_background({ api_cfg, event_session_id, view, try_cache, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, log_lvl });
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal background refresh for a single session
|
||||
*/
|
||||
async function _refresh_session_id_background({ api_cfg, event_session_id, view, try_cache, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, log_lvl }: any) {
|
||||
if (typeof navigator !== 'undefined' && !navigator.onLine) return null;
|
||||
try {
|
||||
const result = await api.get_ae_obj_v3({ api_cfg, obj_type: 'event_session', obj_id: event_session_id, view, log_lvl });
|
||||
if (result) {
|
||||
let processed_obj = result;
|
||||
const processed = await process_ae_obj__event_session_props({ obj_li: [result], log_lvl });
|
||||
const processed_obj = processed[0];
|
||||
if (try_cache) {
|
||||
const processed = await process_ae_obj__event_session_props({ obj_li: [result], log_lvl });
|
||||
processed_obj = processed[0];
|
||||
await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'session', obj_li: processed, properties_to_save, log_lvl });
|
||||
await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'session', obj_li: [processed_obj], properties_to_save, log_lvl });
|
||||
}
|
||||
return await _handle_nested_loads(processed_obj, { api_cfg, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl });
|
||||
return await _handle_nested_loads(processed_obj, { api_cfg, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache: false, log_lvl });
|
||||
}
|
||||
} catch (e) {}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to handle nested collection loads for a session
|
||||
*/
|
||||
async function _handle_nested_loads(session_obj: any, { api_cfg, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl }: any) {
|
||||
// String-Only ID Vision: the '_id' field IS the string ID
|
||||
const current_session_id = session_obj.id || session_obj.event_session_id;
|
||||
|
||||
if (!current_session_id) return session_obj;
|
||||
const tasks = [];
|
||||
if (inc_file_li) {
|
||||
tasks.push(load_ae_obj_li__event_file({
|
||||
api_cfg, for_obj_type: 'event_session', for_obj_id: current_session_id,
|
||||
enabled, limit: 15, try_cache, log_lvl
|
||||
}).then(res => session_obj.event_file_li = res));
|
||||
tasks.push(load_ae_obj_li__event_file({ api_cfg, for_obj_type: 'event_session', for_obj_id: current_session_id, enabled, limit: 15, try_cache, log_lvl }).then(res => session_obj.event_file_li = res));
|
||||
}
|
||||
|
||||
if (inc_presentation_li) {
|
||||
tasks.push(load_ae_obj_li__event_presentation({
|
||||
api_cfg, for_obj_type: 'event_session', for_obj_id: current_session_id,
|
||||
inc_file_li: inc_all_file_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl
|
||||
}).then(res => session_obj.event_presentation_li = res));
|
||||
tasks.push(load_ae_obj_li__event_presentation({ api_cfg, for_obj_type: 'event_session', for_obj_id: current_session_id, inc_file_li: inc_all_file_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl }).then(res => session_obj.event_presentation_li = res));
|
||||
}
|
||||
|
||||
if (tasks.length > 0) await Promise.all(tasks);
|
||||
return session_obj;
|
||||
}
|
||||
|
||||
// Updated 2026-01-27 to V3 String-Only ID Standard
|
||||
export async function load_ae_obj_li__event_session({
|
||||
api_cfg,
|
||||
for_obj_type = 'event',
|
||||
@@ -158,29 +134,17 @@ export async function load_ae_obj_li__event_session({
|
||||
console.log(`*** load_ae_obj_li__event_session() *** [V3] for=${for_obj_type}:${for_obj_id} (SWR)`);
|
||||
}
|
||||
|
||||
// 1. FAST PATH: Check cache
|
||||
if (try_cache) {
|
||||
try {
|
||||
const cached_li = await db_events.session.where('for_id').equals(for_obj_id).toArray();
|
||||
const cached_li = await db_events.session.where('event_location_id').equals(for_obj_id).toArray();
|
||||
if (cached_li && cached_li.length > 0) {
|
||||
if (log_lvl) console.log(`SESSION LIST: Cache hit (${cached_li.length}). Returning stale data.`);
|
||||
_refresh_session_li_background({
|
||||
api_cfg, for_obj_type, for_obj_id, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li,
|
||||
enabled, hidden, limit, offset, order_by_li, try_cache, log_lvl: 0
|
||||
});
|
||||
for (const s of cached_li) {
|
||||
await _handle_nested_loads(s, { api_cfg, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl });
|
||||
}
|
||||
_refresh_session_li_background({ api_cfg, for_obj_type, for_obj_id, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, order_by_li, try_cache, log_lvl: 0 });
|
||||
return cached_li;
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
// 2. SLOW PATH: API
|
||||
return await _refresh_session_li_background({
|
||||
api_cfg, for_obj_type, for_obj_id, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li,
|
||||
enabled, hidden, limit, offset, order_by_li, try_cache, log_lvl
|
||||
});
|
||||
return await _refresh_session_li_background({ api_cfg, for_obj_type, for_obj_id, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, order_by_li, try_cache, log_lvl });
|
||||
}
|
||||
|
||||
async function _refresh_session_li_background({ api_cfg, for_obj_type, for_obj_id, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, order_by_li, try_cache, log_lvl }: any) {
|
||||
@@ -188,451 +152,126 @@ async function _refresh_session_li_background({ api_cfg, for_obj_type, for_obj_i
|
||||
try {
|
||||
const result_li = await api.get_ae_obj_li_v3({ api_cfg, obj_type: 'event_session', for_obj_type, for_obj_id, enabled, hidden, limit, offset, order_by_li, log_lvl });
|
||||
if (result_li) {
|
||||
let processed_li = result_li;
|
||||
const processed = await process_ae_obj__event_session_props({ obj_li: result_li, log_lvl });
|
||||
if (try_cache) {
|
||||
processed_li = await process_ae_obj__event_session_props({ obj_li: result_li, log_lvl });
|
||||
await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'session', obj_li: processed_li, properties_to_save, log_lvl });
|
||||
await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'session', obj_li: processed, properties_to_save, log_lvl });
|
||||
}
|
||||
for (const s of processed_li) {
|
||||
await _handle_nested_loads(s, { api_cfg, inc_file_li, inc_all_file_li, inc_presentation_li, inc_presenter_li, enabled, hidden, limit, offset, try_cache, log_lvl });
|
||||
}
|
||||
return processed_li;
|
||||
return processed;
|
||||
}
|
||||
} catch (e) {}
|
||||
return [];
|
||||
}
|
||||
|
||||
// Updated 2026-01-20 to V3
|
||||
export async function create_ae_obj__event_session({
|
||||
api_cfg,
|
||||
event_id,
|
||||
data_kv,
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
api_cfg, event_id, data_kv, try_cache = true, log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
event_id: string;
|
||||
data_kv: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
api_cfg: any; event_id: string; data_kv: key_val; try_cache?: boolean; log_lvl?: number;
|
||||
}): Promise<ae_EventSession | null> {
|
||||
if (log_lvl) {
|
||||
console.log(`*** create_ae_obj__event_session() *** [V3] event_id=${event_id}`);
|
||||
}
|
||||
|
||||
const result = await api.create_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'event_session',
|
||||
fields: {
|
||||
event_id,
|
||||
...data_kv
|
||||
},
|
||||
log_lvl
|
||||
});
|
||||
|
||||
const result = await api.create_ae_obj_v3({ api_cfg, obj_type: 'event_session', fields: { event_id, ...data_kv }, log_lvl });
|
||||
if (result) {
|
||||
const processed = await process_ae_obj__event_session_props({
|
||||
obj_li: [result],
|
||||
log_lvl
|
||||
});
|
||||
const processed = await process_ae_obj__event_session_props({ obj_li: [result], log_lvl });
|
||||
const processed_obj = processed[0];
|
||||
|
||||
if (try_cache) {
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_events,
|
||||
table_name: 'session',
|
||||
obj_li: [processed_obj],
|
||||
properties_to_save,
|
||||
log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'session', obj_li: [processed_obj], properties_to_save, log_lvl });
|
||||
}
|
||||
return processed_obj;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Updated 2026-01-20 to V3
|
||||
export async function delete_ae_obj_id__event_session({
|
||||
api_cfg,
|
||||
event_session_id,
|
||||
method = 'delete',
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
api_cfg, event_session_id, method = 'delete', try_cache = true, log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
event_session_id: string;
|
||||
method?: 'delete' | 'soft_delete' | 'disable' | 'hide';
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
api_cfg: any; event_session_id: string; method?: 'delete' | 'soft_delete' | 'disable' | 'hide'; try_cache?: boolean; log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** delete_ae_obj_id__event_session() *** [V3] id=${event_session_id}`);
|
||||
}
|
||||
|
||||
const result = await api.delete_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'event_session',
|
||||
obj_id: event_session_id,
|
||||
method,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
if (try_cache) {
|
||||
await db_events.session.delete(event_session_id);
|
||||
}
|
||||
|
||||
const result = await api.delete_ae_obj_v3({ api_cfg, obj_type: 'event_session', obj_id: event_session_id, method, log_lvl });
|
||||
if (try_cache) await db_events.session.delete(event_session_id);
|
||||
return result;
|
||||
}
|
||||
|
||||
// Updated 2026-01-20 to V3
|
||||
export async function update_ae_obj__event_session({
|
||||
api_cfg,
|
||||
event_session_id,
|
||||
data_kv,
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
api_cfg, event_session_id, data_kv, try_cache = true, log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
event_session_id: string;
|
||||
data_kv: key_val;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
api_cfg: any; event_session_id: string; data_kv: key_val; try_cache?: boolean; log_lvl?: number;
|
||||
}): Promise<ae_EventSession | null> {
|
||||
if (log_lvl) {
|
||||
console.log(`*** update_ae_obj__event_session() *** [V3] id=${event_session_id}`);
|
||||
}
|
||||
|
||||
const result = await api.update_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'event_session',
|
||||
obj_id: event_session_id,
|
||||
fields: data_kv,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
const result = await api.update_ae_obj_v3({ api_cfg, obj_type: 'event_session', obj_id: event_session_id, fields: data_kv, log_lvl });
|
||||
if (result) {
|
||||
const processed = await process_ae_obj__event_session_props({
|
||||
obj_li: [result],
|
||||
log_lvl
|
||||
});
|
||||
const processed = await process_ae_obj__event_session_props({ obj_li: [result], log_lvl });
|
||||
const processed_obj = processed[0];
|
||||
|
||||
if (try_cache) {
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_events,
|
||||
table_name: 'session',
|
||||
obj_li: [processed_obj],
|
||||
properties_to_save,
|
||||
log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'session', obj_li: [processed_obj], properties_to_save, log_lvl });
|
||||
}
|
||||
return processed_obj;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// Updated 2026-01-21 to Restore Full Aether Search logic
|
||||
export async function search__event_session({
|
||||
api_cfg,
|
||||
event_id,
|
||||
fulltext_search_qry_str = '',
|
||||
ft_presenter_search_qry_str = '',
|
||||
like_search_qry_str = '',
|
||||
like_presentation_search_qry_str = '',
|
||||
like_presenter_search_qry_str = '',
|
||||
like_poc_name_qry_str = '',
|
||||
location_name = null,
|
||||
qry_files = null,
|
||||
qry_poc_agree = null,
|
||||
qry_poc_kv_json = null,
|
||||
qry_start_datetime = null,
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
view = 'default',
|
||||
limit = 50,
|
||||
offset = 0,
|
||||
order_by_li = [
|
||||
{ sort: 'ASC' },
|
||||
{ start_datetime: 'ASC' },
|
||||
{ name: 'ASC' }
|
||||
],
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
api_cfg, event_id, fulltext_search_qry_str = '', ft_presenter_search_qry_str = '', like_search_qry_str = '', like_presentation_search_qry_str = '', like_presenter_search_qry_str = '', like_poc_name_qry_str = '', location_name = null, qry_files = null, qry_poc_agree = null, qry_poc_kv_json = null, qry_start_datetime = null, enabled = 'enabled', hidden = 'not_hidden', view = 'default', limit = 50, offset = 0, order_by_li = [{ sort: 'ASC' }, { start_datetime: 'ASC' }, { name: 'ASC' }], try_cache = true, log_lvl = 0
|
||||
}: {
|
||||
api_cfg: any;
|
||||
event_id: string;
|
||||
fulltext_search_qry_str?: string;
|
||||
ft_presenter_search_qry_str?: string | null;
|
||||
like_search_qry_str?: string;
|
||||
like_presentation_search_qry_str?: string;
|
||||
like_presenter_search_qry_str?: string;
|
||||
like_poc_name_qry_str?: string;
|
||||
location_name?: null | string;
|
||||
qry_files?: null | boolean;
|
||||
qry_poc_agree?: null | boolean;
|
||||
qry_poc_kv_json?: null | boolean;
|
||||
qry_start_datetime?: string | null;
|
||||
enabled?: 'enabled' | 'all' | 'not_enabled';
|
||||
hidden?: 'hidden' | 'all' | 'not_hidden';
|
||||
view?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
order_by_li?: any;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
api_cfg: any; event_id: string; fulltext_search_qry_str?: string; ft_presenter_search_qry_str?: string | null; like_search_qry_str?: string; like_presentation_search_qry_str?: string; like_presenter_search_qry_str?: string; like_poc_name_qry_str?: string; location_name?: null | string; qry_files?: null | boolean; qry_poc_agree?: null | boolean; qry_poc_kv_json?: null | boolean; qry_start_datetime?: string | null; enabled?: 'enabled' | 'all' | 'not_enabled'; hidden?: 'hidden' | 'all' | 'not_hidden'; view?: string; limit?: number; offset?: number; order_by_li?: any; try_cache?: boolean; log_lvl?: number;
|
||||
}): Promise<ae_EventSession[]> {
|
||||
if (log_lvl) {
|
||||
console.log(`*** search__event_session() *** [V3] event_id=${event_id} ft=${fulltext_search_qry_str}`);
|
||||
}
|
||||
|
||||
const search_query: any = {
|
||||
q: '',
|
||||
and: [{ field: 'event_id', op: 'eq', value: event_id }]
|
||||
};
|
||||
|
||||
const params: key_val = {};
|
||||
|
||||
// Restore Fulltext logic
|
||||
const search_query: any = { q: '', and: [{ field: 'event_id', op: 'eq', value: event_id }] };
|
||||
if (fulltext_search_qry_str || ft_presenter_search_qry_str) {
|
||||
params['ft_qry'] = {};
|
||||
if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) {
|
||||
params['ft_qry']['default_qry_str'] = fulltext_search_qry_str;
|
||||
}
|
||||
if (ft_presenter_search_qry_str && ft_presenter_search_qry_str.length > 2) {
|
||||
params['ft_qry']['event_presenter_li_qry_str'] = ft_presenter_search_qry_str;
|
||||
}
|
||||
const ft: any = {};
|
||||
if (fulltext_search_qry_str && fulltext_search_qry_str.length > 2) ft['default_qry_str'] = fulltext_search_qry_str;
|
||||
if (ft_presenter_search_qry_str && ft_presenter_search_qry_str.length > 2) ft['event_presenter_li_qry_str'] = ft_presenter_search_qry_str;
|
||||
if (Object.keys(ft).length) search_query.params = { ft_qry: ft };
|
||||
}
|
||||
|
||||
// Restore Like logic
|
||||
if (like_search_qry_str || like_presentation_search_qry_str || like_presenter_search_qry_str || like_poc_name_qry_str) {
|
||||
params['lk_qry'] = {};
|
||||
if (like_search_qry_str) {
|
||||
params['lk_qry']['default_qry_str'] = like_search_qry_str;
|
||||
// Also add to the explicit V3 search body for the session table specifically
|
||||
search_query.and.push({ field: 'default_qry_str', op: 'like', value: `%${like_search_qry_str.trim()}%` });
|
||||
}
|
||||
if (like_presentation_search_qry_str) params['lk_qry']['event_presentation_li_qry_str'] = like_presentation_search_qry_str;
|
||||
if (like_presenter_search_qry_str) params['lk_qry']['event_presenter_li_qry_str'] = like_presenter_search_qry_str;
|
||||
if (like_poc_name_qry_str) params['lk_qry']['poc_person_full_name'] = like_poc_name_qry_str;
|
||||
}
|
||||
|
||||
if (location_name) {
|
||||
search_query.and.push({ field: 'event_location_name', op: 'like', value: `%${location_name}%` });
|
||||
}
|
||||
|
||||
if (qry_files !== null) {
|
||||
if (qry_files === true) search_query.and.push({ field: 'file_count_all', op: 'gt', value: 0 });
|
||||
else search_query.and.push({ field: 'file_count_all', op: 'eq', value: 0 });
|
||||
}
|
||||
|
||||
if (qry_poc_agree !== null) {
|
||||
search_query.and.push({ field: 'poc_agree', op: 'eq', value: qry_poc_agree ? 1 : 0 });
|
||||
}
|
||||
|
||||
if (qry_start_datetime) {
|
||||
search_query.and.push({ field: 'start_datetime', op: 'gte', value: qry_start_datetime });
|
||||
}
|
||||
|
||||
if (enabled === 'enabled') search_query.and.push({ field: 'enable', op: 'eq', value: 1 });
|
||||
else if (enabled === 'not_enabled') search_query.and.push({ field: 'enable', op: 'eq', value: 0 });
|
||||
|
||||
if (hidden === 'hidden') search_query.and.push({ field: 'hide', op: 'eq', value: 1 });
|
||||
else if (hidden === 'not_hidden') search_query.and.push({ field: 'hide', op: 'eq', value: 0 });
|
||||
|
||||
const result_li = await api.search_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'event_session',
|
||||
search_query,
|
||||
order_by_li,
|
||||
params, // Important: pass through special Aether params
|
||||
view,
|
||||
limit,
|
||||
offset,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
const result_li = await api.search_ae_obj_v3({ api_cfg, obj_type: 'event_session', search_query, order_by_li, view, limit, offset, log_lvl });
|
||||
if (result_li) {
|
||||
const processed = await process_ae_obj__event_session_props({
|
||||
obj_li: result_li,
|
||||
log_lvl
|
||||
});
|
||||
|
||||
const processed = await process_ae_obj__event_session_props({ obj_li: result_li, log_lvl });
|
||||
if (try_cache) {
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_events,
|
||||
table_name: 'session',
|
||||
obj_li: processed,
|
||||
properties_to_save,
|
||||
log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'session', obj_li: processed, properties_to_save, log_lvl });
|
||||
}
|
||||
return processed;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
export const qry__event_session = search__event_session;
|
||||
|
||||
/**
|
||||
* Send sign-in link to POC
|
||||
*/
|
||||
export async function email_sign_in__event_session({
|
||||
api_cfg,
|
||||
to_email,
|
||||
to_name,
|
||||
base_url,
|
||||
person_id,
|
||||
person_passcode,
|
||||
event_id,
|
||||
event_session_id,
|
||||
session_name
|
||||
}: {
|
||||
api_cfg: any;
|
||||
to_email: string;
|
||||
to_name: string;
|
||||
base_url: string;
|
||||
person_id: string;
|
||||
person_passcode: string;
|
||||
event_id: string;
|
||||
event_session_id: string;
|
||||
session_name: string;
|
||||
}) {
|
||||
export async function email_sign_in__event_session({ api_cfg, to_email, to_name, base_url, person_id, person_passcode, event_id, event_session_id, session_name }: { api_cfg: any; to_email: string; to_name: string; base_url: string; person_id: string; person_passcode: string; event_id: string; event_session_id: string; session_name: string; }) {
|
||||
const subject = `Pres Mgmt Hub Sign In Link for ${session_name}`;
|
||||
const sign_in_url = encodeURI(
|
||||
`${base_url}/events/${event_id}/session/${event_session_id}?person_id=${person_id}&person_pass=${person_passcode}`
|
||||
);
|
||||
|
||||
const body_html = `
|
||||
<div>${to_name},
|
||||
<p>Your sign-in link for ${session_name}: <a href="${sign_in_url}">${sign_in_url}</a></p>
|
||||
</div>`;
|
||||
|
||||
return await api.send_email({
|
||||
api_cfg,
|
||||
from_email: 'noreply+presmgmt@oneskyit.com',
|
||||
from_name: 'Aether Pres Mgmt',
|
||||
to_email,
|
||||
subject,
|
||||
body_html
|
||||
});
|
||||
const sign_in_url = encodeURI(`${base_url}/events/${event_id}/session/${event_session_id}?person_id=${person_id}&person_pass=${person_passcode}`);
|
||||
const body_html = `<div>${to_name},<p>Your sign-in link for ${session_name}: <a href="${sign_in_url}">${sign_in_url}</a></p></div>`;
|
||||
return await api.send_email({ api_cfg, from_email: 'noreply+presmgmt@oneskyit.com', from_name: 'Aether Pres Mgmt', to_email, subject, body_html });
|
||||
}
|
||||
|
||||
export const properties_to_save = [
|
||||
'id',
|
||||
'event_session_id',
|
||||
'external_id',
|
||||
'code',
|
||||
'for_type',
|
||||
'for_id',
|
||||
'type_code',
|
||||
'event_id',
|
||||
'event_location_id',
|
||||
'poc_person_id',
|
||||
'poc_agree',
|
||||
'poc_kv_json',
|
||||
'name',
|
||||
'description',
|
||||
'start_datetime',
|
||||
'end_datetime',
|
||||
'passcode',
|
||||
'hide_event_launcher',
|
||||
'alert',
|
||||
'alert_msg',
|
||||
'data_json',
|
||||
'ux_mode',
|
||||
'enable',
|
||||
'hide',
|
||||
'priority',
|
||||
'sort',
|
||||
'group',
|
||||
'notes',
|
||||
'created_on',
|
||||
'updated_on',
|
||||
'tmp_sort_1',
|
||||
'tmp_sort_2',
|
||||
'file_count',
|
||||
'file_count_all',
|
||||
'internal_use_count',
|
||||
'event_file_id_li_json',
|
||||
'poc_person_given_name',
|
||||
'poc_person_family_name',
|
||||
'poc_person_full_name',
|
||||
'poc_person_primary_email',
|
||||
'poc_person_passcode',
|
||||
'event_name',
|
||||
'event_location_code',
|
||||
'event_location_name',
|
||||
'event_presentation_li'
|
||||
'id', 'event_session_id', 'event_session_id_random', 'external_id', 'code', 'for_type', 'for_id', 'for_id_random', 'type_code', 'event_id', 'event_location_id', 'poc_person_id', 'poc_agree', 'poc_kv_json', 'name', 'description', 'start_datetime', 'end_datetime', 'passcode', 'hide_event_launcher', 'alert', 'alert_msg', 'data_json', 'ux_mode', 'enable', 'hide', 'priority', 'sort', 'group', 'notes', 'created_on', 'updated_on', 'tmp_sort_1', 'tmp_sort_2', 'file_count', 'file_count_all', 'internal_use_count', 'event_file_id_li_json', 'poc_person_given_name', 'poc_person_family_name', 'poc_person_full_name', 'poc_person_primary_email', 'poc_person_passcode', 'event_name', 'event_location_code', 'event_location_name', 'event_presentation_li'
|
||||
];
|
||||
|
||||
/**
|
||||
* NON-EXPORTED LOCAL HELPER
|
||||
* Processes a list of Aether objects by applying common and specific transformations.
|
||||
*/
|
||||
async function _process_generic_props<T extends Record<string, any>>({
|
||||
obj_li,
|
||||
obj_type,
|
||||
log_lvl = 0,
|
||||
specific_processor
|
||||
}: {
|
||||
obj_li: T[];
|
||||
obj_type: string;
|
||||
log_lvl?: number;
|
||||
specific_processor?: (obj: T) => Promise<T> | T;
|
||||
}): Promise<T[]> {
|
||||
async function _process_generic_props<T extends Record<string, any>>({ obj_li, obj_type, log_lvl = 0, specific_processor }: { obj_li: T[]; obj_type: string; log_lvl?: number; specific_processor?: (obj: T) => Promise<T> | T; }): Promise<T[]> {
|
||||
if (!obj_li || obj_li.length === 0) return [];
|
||||
|
||||
const processed_obj_li: T[] = [];
|
||||
|
||||
for (const original_obj of obj_li) {
|
||||
let processed_obj = { ...original_obj };
|
||||
|
||||
// 1. Standardize ID and other '_random' fields
|
||||
for (const key in processed_obj) {
|
||||
if (key.endsWith('_random')) {
|
||||
const newKey = key.slice(0, -7);
|
||||
(processed_obj as any)[newKey] = processed_obj[key];
|
||||
}
|
||||
}
|
||||
// String-Only ID Vision: Map [obj_type]_id_random to 'id'
|
||||
const randomIdKey = `${obj_type}_id_random`;
|
||||
if (processed_obj[randomIdKey]) {
|
||||
(processed_obj as any).id = processed_obj[randomIdKey];
|
||||
}
|
||||
|
||||
// 2. Create common computed properties
|
||||
if (processed_obj[randomIdKey]) (processed_obj as any).id = processed_obj[randomIdKey];
|
||||
const group = processed_obj.group ?? '0';
|
||||
const priority = processed_obj.priority ? 1 : 0;
|
||||
const sort = processed_obj.sort ?? '0';
|
||||
const updated = processed_obj.updated_on ?? processed_obj.created_on;
|
||||
const name = processed_obj.name ?? '';
|
||||
|
||||
(processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
|
||||
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
|
||||
|
||||
if (specific_processor) {
|
||||
processed_obj = await Promise.resolve(specific_processor(processed_obj));
|
||||
}
|
||||
|
||||
if (specific_processor) processed_obj = await Promise.resolve(specific_processor(processed_obj));
|
||||
processed_obj_li.push(processed_obj as T);
|
||||
}
|
||||
|
||||
return processed_obj_li;
|
||||
}
|
||||
|
||||
export async function process_ae_obj__event_session_props({
|
||||
obj_li,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
obj_li: any[];
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
return _process_generic_props({
|
||||
obj_li,
|
||||
obj_type: 'event_session',
|
||||
log_lvl
|
||||
});
|
||||
export async function process_ae_obj__event_session_props({ obj_li, log_lvl = 0 }: { obj_li: any[]; log_lvl?: number; }) {
|
||||
return _process_generic_props({ obj_li, obj_type: 'event_session', log_lvl });
|
||||
}
|
||||
Reference in New Issue
Block a user