Saving more code clean up and removal

This commit is contained in:
Scott Idem
2026-03-24 11:15:01 -04:00
parent d27ec58fe9
commit 512e5ef87c
25 changed files with 130 additions and 153 deletions

View File

@@ -11,6 +11,88 @@ const ae_promises: key_val = {};
* --- SITE CRUD ---
*/
// Legacy version
// export async function lookup_site_domain({
// api_cfg,
// fqdn,
// view = 'default',
// log_lvl = 0
// }: {
// api_cfg: any;
// fqdn: string;
// view?: string;
// log_lvl?: number;
// }): Promise<ae_SiteDomain | null> {
// if (log_lvl) {
// console.log(`*** lookup_site_domain() *** fqdn=${fqdn}`);
// }
// try {
// // We use get_ae_obj_id_crud because we are looking up by a unique field (fqdn) rather than ID.
// // This is the older method that uses the /crud/site/domain/:id endpoint.
// const result = await api.get_ae_obj_id_crud({
// api_cfg,
// no_account_id: true,
// obj_type: 'site_domain',
// obj_id: fqdn,
// use_alt_table: true,
// use_alt_base: true,
// log_lvl
// });
// if (result) {
// // Standardize and save to cache
// const processed_obj_li = await process_ae_obj__site_domain_props({
// obj_li: [result],
// log_lvl
// });
// await db_save_ae_obj_li__ae_obj({
// db_instance: db_core,
// table_name: 'site_domain',
// obj_li: processed_obj_li,
// properties_to_save: properties_to_save__site_domain,
// log_lvl
// });
// return result;
// }
// } catch (error: any) {
// console.log('Site domain lookup failed (API Error).', error);
// }
// if (log_lvl) console.log('Attempting to load site domain from local cache...');
// const cached = await db_core.site_domain.where('fqdn').equals(fqdn).first();
// if (cached) {
// return cached as any;
// }
// // CRITICAL FALLBACK: If both API and Cache fail, return a "Ghost" site domain object
// // to prevent the 403 error from blocking the UI. Page components will handle empty data.
// console.error('AE_SITE_CRITICAL: Site domain lookup failed API and CACHE. Returning ghost object.');
// return {
// id: 'ghost',
// id_random: 'ghost',
// site_domain_id: 'ghost',
// site_domain_id_random: 'ghost',
// site_id: 'ghost',
// site_id_random: 'ghost',
// account_id: 'ghost',
// account_id_random: 'ghost',
// account_code: 'ghost',
// account_name: 'Ghost Account (Offline)',
// fqdn: fqdn,
// enable: '1',
// header_image_path: '',
// style_href: '',
// google_tracking_id: '',
// access_code_kv_json: {},
// cfg_json: {},
// access_key: '',
// site_domain_access_key: ''
// } as any;
// }
// Updated 2026-01-26 (Cache-First Optimization)
export async function lookup_site_domain({
api_cfg,
fqdn,
@@ -23,88 +105,7 @@ export async function lookup_site_domain({
log_lvl?: number;
}): Promise<ae_SiteDomain | null> {
if (log_lvl) {
console.log(`*** lookup_site_domain() *** fqdn=${fqdn}`);
}
try {
// We use get_ae_obj_id_crud because we are looking up by a unique field (fqdn) rather than ID.
// This is the older method that uses the /crud/site/domain/:id endpoint.
const result = await api.get_ae_obj_id_crud({
api_cfg,
no_account_id: true,
obj_type: 'site_domain',
obj_id: fqdn,
use_alt_table: true,
use_alt_base: true,
log_lvl
});
if (result) {
// Standardize and save to cache
const processed_obj_li = await process_ae_obj__site_domain_props({
obj_li: [result],
log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_core,
table_name: 'site_domain',
obj_li: processed_obj_li,
properties_to_save: properties_to_save__site_domain,
log_lvl
});
return result;
}
} catch (error: any) {
console.log('Site domain lookup failed (API Error).', error);
}
if (log_lvl) console.log('Attempting to load site domain from local cache...');
const cached = await db_core.site_domain.where('fqdn').equals(fqdn).first();
if (cached) {
return cached as any;
}
// CRITICAL FALLBACK: If both API and Cache fail, return a "Ghost" site domain object
// to prevent the 403 error from blocking the UI. Page components will handle empty data.
console.error('AE_SITE_CRITICAL: Site domain lookup failed API and CACHE. Returning ghost object.');
return {
id: 'ghost',
id_random: 'ghost',
site_domain_id: 'ghost',
site_domain_id_random: 'ghost',
site_id: 'ghost',
site_id_random: 'ghost',
account_id: 'ghost',
account_id_random: 'ghost',
account_code: 'ghost',
account_name: 'Ghost Account (Offline)',
fqdn: fqdn,
enable: '1',
header_image_path: '',
style_href: '',
google_tracking_id: '',
access_code_kv_json: {},
cfg_json: {},
access_key: '',
site_domain_access_key: ''
} as any;
}
// Updated 2026-01-26 (Cache-First Optimization)
export async function lookup_site_domain_v3({
api_cfg,
fqdn,
view = 'default',
log_lvl = 0
}: {
api_cfg: any;
fqdn: string;
view?: string;
log_lvl?: number;
}): Promise<ae_SiteDomain | null> {
if (log_lvl) {
console.log(`*** lookup_site_domain_v3() *** fqdn=${fqdn} (Cache-First)`);
console.log(`*** lookup_site_domain() *** fqdn=${fqdn} (Cache-First)`);
}
// 1. FAST PATH: Check local cache first
@@ -115,7 +116,7 @@ export async function lookup_site_domain_v3({
if (log_lvl) console.log('BOOTSTRAP: Cache hit. Returning cached site domain immediately.');
// Trigger background refresh to keep cache fresh, but don't await it
_refresh_site_domain_v3_background({ api_cfg, fqdn, view, log_lvl: 0 });
_refresh_site_domain_background({ api_cfg, fqdn, view, log_lvl: 0 });
return cached as any;
}
@@ -124,13 +125,13 @@ export async function lookup_site_domain_v3({
}
// 2. SLOW PATH: Wait for API if cache is empty
return await _refresh_site_domain_v3_background({ api_cfg, fqdn, view, log_lvl });
return await _refresh_site_domain_background({ api_cfg, fqdn, view, log_lvl });
}
/**
* Internal helper to perform the actual API fetch and cache update
*/
async function _refresh_site_domain_v3_background({ api_cfg, fqdn, view, log_lvl }: any) {
async function _refresh_site_domain_background({ api_cfg, fqdn, view, log_lvl }: any) {
try {
const guest_api_cfg = { ...api_cfg };
guest_api_cfg.headers = { ...api_cfg.headers };