refactor(events): enforce hierarchy consistency and id standardization
This commit is contained in:
@@ -6,6 +6,7 @@ import { db_events } from '$lib/ae_events/db_events';
|
||||
import type { ae_EventLocation } from '$lib/types/ae_types';
|
||||
import { load_ae_obj_li__event_file } from '$lib/ae_events/ae_events__event_file';
|
||||
import { load_ae_obj_li__event_session } from '$lib/ae_events/ae_events__event_session';
|
||||
import { load_ae_obj_li__event_device } from '$lib/ae_events/ae_events__event_device';
|
||||
|
||||
const ae_promises: key_val = {};
|
||||
|
||||
@@ -16,6 +17,9 @@ export async function load_ae_obj_id__event_location({
|
||||
view = 'default',
|
||||
inc_file_li = false,
|
||||
inc_session_li = false,
|
||||
inc_presentation_li = false,
|
||||
inc_presenter_li = false,
|
||||
inc_device_li = false,
|
||||
inc_all_file_li = false,
|
||||
try_cache = true,
|
||||
log_lvl = 0
|
||||
@@ -25,6 +29,9 @@ export async function load_ae_obj_id__event_location({
|
||||
view?: string;
|
||||
inc_file_li?: boolean;
|
||||
inc_session_li?: boolean;
|
||||
inc_presentation_li?: boolean;
|
||||
inc_presenter_li?: boolean;
|
||||
inc_device_li?: boolean;
|
||||
inc_all_file_li?: boolean;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
@@ -38,17 +45,28 @@ export async function load_ae_obj_id__event_location({
|
||||
try {
|
||||
const cached = await db_events.location.get(event_location_id);
|
||||
if (cached) {
|
||||
_refresh_location_id_background({ api_cfg, event_location_id, view, try_cache, inc_file_li, inc_session_li, inc_all_file_li, log_lvl: 0 });
|
||||
return await _handle_nested_loads(cached, { api_cfg, inc_file_li, inc_session_li, inc_all_file_li, log_lvl });
|
||||
_refresh_location_id_background({
|
||||
api_cfg, event_location_id, view, try_cache,
|
||||
inc_file_li, inc_session_li, inc_presentation_li, inc_presenter_li, inc_device_li, inc_all_file_li,
|
||||
log_lvl: 0
|
||||
});
|
||||
return await _handle_nested_loads(cached, {
|
||||
api_cfg, inc_file_li, inc_session_li, inc_presentation_li, inc_presenter_li, inc_device_li, inc_all_file_li,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
// 2. SLOW PATH: Wait for API
|
||||
return await _refresh_location_id_background({ api_cfg, event_location_id, view, try_cache, inc_file_li, inc_session_li, inc_all_file_li, log_lvl });
|
||||
return await _refresh_location_id_background({
|
||||
api_cfg, event_location_id, view, try_cache,
|
||||
inc_file_li, inc_session_li, inc_presentation_li, inc_presenter_li, inc_device_li, inc_all_file_li,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
async function _refresh_location_id_background({ api_cfg, event_location_id, view, try_cache, inc_file_li, inc_session_li, inc_all_file_li, log_lvl }: any) {
|
||||
async function _refresh_location_id_background({ api_cfg, event_location_id, view, try_cache, inc_file_li, inc_session_li, inc_presentation_li, inc_presenter_li, inc_device_li, inc_all_file_li, 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_location', obj_id: event_location_id, view, log_lvl });
|
||||
@@ -58,7 +76,10 @@ async function _refresh_location_id_background({ api_cfg, event_location_id, vie
|
||||
if (try_cache) {
|
||||
await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'location', obj_li: [processed_obj], properties_to_save, log_lvl });
|
||||
}
|
||||
return await _handle_nested_loads(processed_obj, { api_cfg, inc_file_li, inc_session_li, inc_all_file_li, log_lvl });
|
||||
return await _handle_nested_loads(processed_obj, {
|
||||
api_cfg, inc_file_li, inc_session_li, inc_presentation_li, inc_presenter_li, inc_device_li, inc_all_file_li,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
} catch (e) {}
|
||||
return null;
|
||||
@@ -71,6 +92,9 @@ export async function load_ae_obj_li__event_location({
|
||||
for_obj_id,
|
||||
inc_file_li = false,
|
||||
inc_session_li = false,
|
||||
inc_presentation_li = false,
|
||||
inc_presenter_li = false,
|
||||
inc_device_li = false,
|
||||
inc_all_file_li = false,
|
||||
enabled = 'enabled',
|
||||
hidden = 'not_hidden',
|
||||
@@ -91,6 +115,9 @@ export async function load_ae_obj_li__event_location({
|
||||
for_obj_id: string;
|
||||
inc_file_li?: boolean;
|
||||
inc_session_li?: boolean;
|
||||
inc_presentation_li?: boolean;
|
||||
inc_presenter_li?: boolean;
|
||||
inc_device_li?: boolean;
|
||||
inc_all_file_li?: boolean;
|
||||
enabled?: 'enabled' | 'all' | 'not_enabled';
|
||||
hidden?: 'hidden' | 'all' | 'not_hidden';
|
||||
@@ -110,9 +137,17 @@ export async function load_ae_obj_li__event_location({
|
||||
try {
|
||||
const cached_li = await db_events.location.where('event_id').equals(for_obj_id).toArray();
|
||||
if (cached_li && cached_li.length > 0) {
|
||||
_refresh_location_li_background({ api_cfg, for_obj_type, for_obj_id, inc_file_li, inc_session_li, inc_all_file_li, enabled, hidden, view, limit, offset, order_by_li, try_cache, log_lvl: 0 });
|
||||
_refresh_location_li_background({
|
||||
api_cfg, for_obj_type, for_obj_id,
|
||||
inc_file_li, inc_session_li, inc_presentation_li, inc_presenter_li, inc_device_li, inc_all_file_li,
|
||||
enabled, hidden, view, limit, offset, order_by_li, try_cache,
|
||||
log_lvl: 0
|
||||
});
|
||||
for (const loc of cached_li) {
|
||||
_handle_nested_loads(loc, { api_cfg, inc_file_li, inc_session_li, inc_all_file_li, log_lvl: 0 });
|
||||
_handle_nested_loads(loc, {
|
||||
api_cfg, inc_file_li, inc_session_li, inc_presentation_li, inc_presenter_li, inc_device_li, inc_all_file_li,
|
||||
log_lvl: 0
|
||||
});
|
||||
}
|
||||
return cached_li;
|
||||
}
|
||||
@@ -120,10 +155,15 @@ export async function load_ae_obj_li__event_location({
|
||||
}
|
||||
|
||||
// 2. SLOW PATH: API
|
||||
return await _refresh_location_li_background({ api_cfg, for_obj_type, for_obj_id, inc_file_li, inc_session_li, inc_all_file_li, enabled, hidden, view, limit, offset, order_by_li, try_cache, log_lvl });
|
||||
return await _refresh_location_li_background({
|
||||
api_cfg, for_obj_type, for_obj_id,
|
||||
inc_file_li, inc_session_li, inc_presentation_li, inc_presenter_li, inc_device_li, inc_all_file_li,
|
||||
enabled, hidden, view, limit, offset, order_by_li, try_cache,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
async function _refresh_location_li_background({ api_cfg, for_obj_type, for_obj_id, inc_file_li, inc_session_li, inc_all_file_li, enabled, hidden, view, limit, offset, order_by_li, try_cache, log_lvl }: any) {
|
||||
async function _refresh_location_li_background({ api_cfg, for_obj_type, for_obj_id, inc_file_li, inc_session_li, inc_presentation_li, inc_presenter_li, inc_device_li, inc_all_file_li, enabled, hidden, view, limit, offset, order_by_li, try_cache, log_lvl }: any) {
|
||||
if (typeof navigator !== 'undefined' && !navigator.onLine) return [];
|
||||
try {
|
||||
const result_li = await api.get_ae_obj_li_v3({ api_cfg, obj_type: 'event_location', for_obj_type, for_obj_id, enabled, hidden, view, limit, offset, order_by_li, log_lvl });
|
||||
@@ -139,7 +179,10 @@ async function _refresh_location_li_background({ api_cfg, for_obj_type, for_obj_
|
||||
await db_save_ae_obj_li__ae_obj({ db_instance: db_events, table_name: 'location', obj_li: processed, properties_to_save, log_lvl });
|
||||
}
|
||||
for (const loc of processed) {
|
||||
_handle_nested_loads(loc, { api_cfg, inc_file_li, inc_session_li, inc_all_file_li, log_lvl: 0 });
|
||||
_handle_nested_loads(loc, {
|
||||
api_cfg, inc_file_li, inc_session_li, inc_presentation_li, inc_presenter_li, inc_device_li, inc_all_file_li,
|
||||
log_lvl: 0
|
||||
});
|
||||
}
|
||||
return processed;
|
||||
}
|
||||
@@ -150,7 +193,7 @@ async function _refresh_location_li_background({ api_cfg, for_obj_type, for_obj_
|
||||
/**
|
||||
* Handle nested data loads for a single location object.
|
||||
*/
|
||||
async function _handle_nested_loads(location_obj: any, { api_cfg, inc_file_li, inc_session_li, inc_all_file_li, log_lvl }: any) {
|
||||
async function _handle_nested_loads(location_obj: any, { api_cfg, inc_file_li, inc_session_li, inc_presentation_li, inc_presenter_li, inc_device_li, inc_all_file_li, log_lvl }: any) {
|
||||
const current_location_id = location_obj.id || location_obj.event_location_id;
|
||||
if (!current_location_id) return location_obj;
|
||||
|
||||
@@ -165,12 +208,21 @@ async function _handle_nested_loads(location_obj: any, { api_cfg, inc_file_li, i
|
||||
if (inc_session_li) {
|
||||
tasks.push(load_ae_obj_li__event_session({
|
||||
api_cfg, for_obj_type: 'event_location', for_obj_id: current_location_id,
|
||||
inc_file_li: inc_all_file_li, inc_all_file_li: inc_all_file_li,
|
||||
inc_presentation_li: true, inc_presenter_li: true,
|
||||
inc_file_li: inc_all_file_li,
|
||||
inc_all_file_li: inc_all_file_li,
|
||||
inc_presentation_li: inc_presentation_li,
|
||||
inc_presenter_li: inc_presenter_li,
|
||||
enabled: 'enabled', hidden: 'not_hidden', limit: 150, log_lvl
|
||||
}).then(res => location_obj.event_session_obj_li = res));
|
||||
}
|
||||
|
||||
if (inc_device_li) {
|
||||
tasks.push(load_ae_obj_li__event_device({
|
||||
api_cfg, for_obj_type: 'event_location', for_obj_id: current_location_id,
|
||||
enabled: 'all', limit: 50, log_lvl
|
||||
}).then(res => location_obj.event_device_li = res));
|
||||
}
|
||||
|
||||
if (tasks.length > 0) await Promise.all(tasks);
|
||||
return location_obj;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user