refactor: clean up try_cache defaults and add SWR to sponsorship loaders
- Remove vestigial try_cache param from generate_qr_code (never used in body) - Remove vestigial try_cache from ae_core_functions: load_ae_obj_id__site_domain, update_ae_obj_id_crud, update_ae_obj_id_crud_v2 (none referenced it in body) - Add proper SWR pattern to load_ae_obj_id__sponsorship_cfg and load_ae_obj_id__sponsorship; change defaults from false to true - Change load_ae_obj_id__event_file default try_cache from false to true (consistent with load_ae_obj_li__event_file) - Change load_ae_obj_id__hosted_file default try_cache from false to true (consistent with load_ae_obj_li__hosted_file) - Remove stale try_cache arg from element_ae_crud.svelte caller
This commit is contained in:
@@ -52,13 +52,11 @@ const ae_promises: key_val = {}; // Promise<any>;
|
|||||||
async function load_ae_obj_id__site_domain({
|
async function load_ae_obj_id__site_domain({
|
||||||
api_cfg,
|
api_cfg,
|
||||||
fqdn,
|
fqdn,
|
||||||
try_cache = false,
|
|
||||||
timeout = 7000,
|
timeout = 7000,
|
||||||
log_lvl = 0
|
log_lvl = 0
|
||||||
}: {
|
}: {
|
||||||
api_cfg: any;
|
api_cfg: any;
|
||||||
fqdn: string;
|
fqdn: string;
|
||||||
try_cache?: boolean;
|
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
log_lvl?: number;
|
log_lvl?: number;
|
||||||
}) {
|
}) {
|
||||||
@@ -273,7 +271,6 @@ async function update_ae_obj_id_crud({
|
|||||||
field_name,
|
field_name,
|
||||||
new_field_value,
|
new_field_value,
|
||||||
params = {},
|
params = {},
|
||||||
try_cache = false,
|
|
||||||
log_lvl = 0
|
log_lvl = 0
|
||||||
}: {
|
}: {
|
||||||
api_cfg: any;
|
api_cfg: any;
|
||||||
@@ -282,9 +279,8 @@ async function update_ae_obj_id_crud({
|
|||||||
object_reload?: boolean;
|
object_reload?: boolean;
|
||||||
field_name: string;
|
field_name: string;
|
||||||
new_field_value: any;
|
new_field_value: any;
|
||||||
params: any | key_val;
|
params?: any | key_val;
|
||||||
try_cache: boolean;
|
log_lvl?: number;
|
||||||
log_lvl: number;
|
|
||||||
}) {
|
}) {
|
||||||
let patch_result: any = null;
|
let patch_result: any = null;
|
||||||
|
|
||||||
@@ -365,7 +361,6 @@ async function update_ae_obj_id_crud_v2({
|
|||||||
field_name,
|
field_name,
|
||||||
new_field_value,
|
new_field_value,
|
||||||
params = {},
|
params = {},
|
||||||
try_cache = false,
|
|
||||||
log_lvl = 0
|
log_lvl = 0
|
||||||
}: {
|
}: {
|
||||||
api_cfg: any;
|
api_cfg: any;
|
||||||
@@ -375,7 +370,6 @@ async function update_ae_obj_id_crud_v2({
|
|||||||
field_name: string;
|
field_name: string;
|
||||||
new_field_value: any;
|
new_field_value: any;
|
||||||
params?: any | key_val;
|
params?: any | key_val;
|
||||||
try_cache?: boolean;
|
|
||||||
log_lvl?: number;
|
log_lvl?: number;
|
||||||
}) {
|
}) {
|
||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ export async function load_ae_obj_id__hosted_file({
|
|||||||
api_cfg,
|
api_cfg,
|
||||||
hosted_file_id,
|
hosted_file_id,
|
||||||
view = 'default',
|
view = 'default',
|
||||||
try_cache = false,
|
try_cache = true,
|
||||||
log_lvl = 0
|
log_lvl = 0
|
||||||
}: {
|
}: {
|
||||||
api_cfg: any;
|
api_cfg: any;
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ export async function generate_qr_code({
|
|||||||
obj_id,
|
obj_id,
|
||||||
str, // For encoding a string (like a URL) into a QR code.
|
str, // For encoding a string (like a URL) into a QR code.
|
||||||
return_blob = true, // blob or url?
|
return_blob = true, // blob or url?
|
||||||
try_cache = false,
|
|
||||||
log_lvl = 0
|
log_lvl = 0
|
||||||
}: {
|
}: {
|
||||||
api_cfg: any;
|
api_cfg: any;
|
||||||
@@ -31,7 +30,6 @@ export async function generate_qr_code({
|
|||||||
obj_id?: string;
|
obj_id?: string;
|
||||||
str?: string;
|
str?: string;
|
||||||
return_blob?: boolean;
|
return_blob?: boolean;
|
||||||
try_cache?: boolean;
|
|
||||||
log_lvl?: number;
|
log_lvl?: number;
|
||||||
}) {
|
}) {
|
||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export async function load_ae_obj_id__event_file({
|
|||||||
event_file_id,
|
event_file_id,
|
||||||
inc_hosted_file = false,
|
inc_hosted_file = false,
|
||||||
view = 'default',
|
view = 'default',
|
||||||
try_cache = false,
|
try_cache = true,
|
||||||
log_lvl = 0
|
log_lvl = 0
|
||||||
}: {
|
}: {
|
||||||
api_cfg: any;
|
api_cfg: any;
|
||||||
|
|||||||
@@ -188,11 +188,11 @@ async function _process_generic_props<T extends Record<string, any>>({
|
|||||||
return processed_obj_li;
|
return processed_obj_li;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updated 2026-01-20 to V3
|
// Updated 2026-03-11: SWR pattern
|
||||||
export async function load_ae_obj_id__sponsorship_cfg({
|
export async function load_ae_obj_id__sponsorship_cfg({
|
||||||
api_cfg,
|
api_cfg,
|
||||||
sponsorship_cfg_id,
|
sponsorship_cfg_id,
|
||||||
try_cache = false,
|
try_cache = true,
|
||||||
log_lvl = 0
|
log_lvl = 0
|
||||||
}: {
|
}: {
|
||||||
api_cfg: any;
|
api_cfg: any;
|
||||||
@@ -201,22 +201,36 @@ export async function load_ae_obj_id__sponsorship_cfg({
|
|||||||
log_lvl?: number;
|
log_lvl?: number;
|
||||||
}): Promise<ae_SponsorshipCfg | null> {
|
}): Promise<ae_SponsorshipCfg | null> {
|
||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
console.log(`*** load_ae_obj_id__sponsorship_cfg() *** [V3] id=${sponsorship_cfg_id}`);
|
console.log(`*** load_ae_obj_id__sponsorship_cfg() *** [V3] id=${sponsorship_cfg_id} (SWR)`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sponsorship_cfg_obj_get_result = await api.get_ae_obj_v3({
|
// 1. FAST PATH: Cache hit
|
||||||
|
if (try_cache) {
|
||||||
|
try {
|
||||||
|
const cached = await db_sponsorships.cfg.get(sponsorship_cfg_id);
|
||||||
|
if (cached) {
|
||||||
|
_refresh_sponsorship_cfg_id_background({ api_cfg, sponsorship_cfg_id, try_cache, log_lvl: 0 });
|
||||||
|
return cached as unknown as ae_SponsorshipCfg;
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. SLOW PATH: Wait for API
|
||||||
|
return await _refresh_sponsorship_cfg_id_background({ api_cfg, sponsorship_cfg_id, try_cache, log_lvl });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function _refresh_sponsorship_cfg_id_background({ api_cfg, sponsorship_cfg_id, try_cache, log_lvl }: any) {
|
||||||
|
if (typeof navigator !== 'undefined' && !navigator.onLine) return null;
|
||||||
|
try {
|
||||||
|
const result = await api.get_ae_obj_v3({
|
||||||
api_cfg,
|
api_cfg,
|
||||||
obj_type: 'sponsorship_cfg',
|
obj_type: 'sponsorship_cfg',
|
||||||
obj_id: sponsorship_cfg_id,
|
obj_id: sponsorship_cfg_id,
|
||||||
log_lvl
|
log_lvl
|
||||||
});
|
});
|
||||||
|
if (result) {
|
||||||
if (sponsorship_cfg_obj_get_result) {
|
|
||||||
if (try_cache) {
|
if (try_cache) {
|
||||||
const processed_obj_li = await process_ae_obj__sponsorship_cfg_props({
|
const processed_obj_li = await process_ae_obj__sponsorship_cfg_props({ obj_li: [result], log_lvl });
|
||||||
obj_li: [sponsorship_cfg_obj_get_result],
|
|
||||||
log_lvl
|
|
||||||
});
|
|
||||||
await db_save_ae_obj_li__ae_obj({
|
await db_save_ae_obj_li__ae_obj({
|
||||||
db_instance: db_sponsorships,
|
db_instance: db_sponsorships,
|
||||||
table_name: 'cfg',
|
table_name: 'cfg',
|
||||||
@@ -225,16 +239,17 @@ export async function load_ae_obj_id__sponsorship_cfg({
|
|||||||
log_lvl
|
log_lvl
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return sponsorship_cfg_obj_get_result;
|
return result;
|
||||||
}
|
}
|
||||||
|
} catch (e) {}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updated 2026-01-20 to V3
|
// Updated 2026-03-11: SWR pattern
|
||||||
export async function load_ae_obj_id__sponsorship({
|
export async function load_ae_obj_id__sponsorship({
|
||||||
api_cfg,
|
api_cfg,
|
||||||
sponsorship_id,
|
sponsorship_id,
|
||||||
try_cache = false,
|
try_cache = true,
|
||||||
log_lvl = 0
|
log_lvl = 0
|
||||||
}: {
|
}: {
|
||||||
api_cfg: any;
|
api_cfg: any;
|
||||||
@@ -243,22 +258,36 @@ export async function load_ae_obj_id__sponsorship({
|
|||||||
log_lvl?: number;
|
log_lvl?: number;
|
||||||
}): Promise<ae_Sponsorship | null> {
|
}): Promise<ae_Sponsorship | null> {
|
||||||
if (log_lvl) {
|
if (log_lvl) {
|
||||||
console.log(`*** load_ae_obj_id__sponsorship() *** [V3] id=${sponsorship_id}`);
|
console.log(`*** load_ae_obj_id__sponsorship() *** [V3] id=${sponsorship_id} (SWR)`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const sponsorship_obj_get_result = await api.get_ae_obj_v3({
|
// 1. FAST PATH: Cache hit
|
||||||
|
if (try_cache) {
|
||||||
|
try {
|
||||||
|
const cached = await db_sponsorships.sponsorship.get(sponsorship_id);
|
||||||
|
if (cached) {
|
||||||
|
_refresh_sponsorship_id_background({ api_cfg, sponsorship_id, try_cache, log_lvl: 0 });
|
||||||
|
return cached as unknown as ae_Sponsorship;
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. SLOW PATH: Wait for API
|
||||||
|
return await _refresh_sponsorship_id_background({ api_cfg, sponsorship_id, try_cache, log_lvl });
|
||||||
|
}
|
||||||
|
|
||||||
|
async function _refresh_sponsorship_id_background({ api_cfg, sponsorship_id, try_cache, log_lvl }: any) {
|
||||||
|
if (typeof navigator !== 'undefined' && !navigator.onLine) return null;
|
||||||
|
try {
|
||||||
|
const result = await api.get_ae_obj_v3({
|
||||||
api_cfg,
|
api_cfg,
|
||||||
obj_type: 'sponsorship',
|
obj_type: 'sponsorship',
|
||||||
obj_id: sponsorship_id,
|
obj_id: sponsorship_id,
|
||||||
log_lvl
|
log_lvl
|
||||||
});
|
});
|
||||||
|
if (result) {
|
||||||
if (sponsorship_obj_get_result) {
|
|
||||||
if (try_cache) {
|
if (try_cache) {
|
||||||
const processed_obj_li = await process_ae_obj__sponsorship_props({
|
const processed_obj_li = await process_ae_obj__sponsorship_props({ obj_li: [result], log_lvl });
|
||||||
obj_li: [sponsorship_obj_get_result],
|
|
||||||
log_lvl
|
|
||||||
});
|
|
||||||
await db_save_ae_obj_li__ae_obj({
|
await db_save_ae_obj_li__ae_obj({
|
||||||
db_instance: db_sponsorships,
|
db_instance: db_sponsorships,
|
||||||
table_name: 'sponsorship',
|
table_name: 'sponsorship',
|
||||||
@@ -267,8 +296,9 @@ export async function load_ae_obj_id__sponsorship({
|
|||||||
log_lvl
|
log_lvl
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return sponsorship_obj_get_result;
|
return result;
|
||||||
}
|
}
|
||||||
|
} catch (e) {}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -125,7 +125,6 @@
|
|||||||
field_name: field_name,
|
field_name: field_name,
|
||||||
new_field_value: new_field_value,
|
new_field_value: new_field_value,
|
||||||
params: {},
|
params: {},
|
||||||
try_cache: true, // Defaulting to true as per project preference
|
|
||||||
log_lvl: 0
|
log_lvl: 0
|
||||||
})
|
})
|
||||||
.then(function (results: any) {
|
.then(function (results: any) {
|
||||||
|
|||||||
Reference in New Issue
Block a user