More work on page load and cache checking
This commit is contained in:
@@ -215,8 +215,8 @@ let trusted_refresh_time = trusted_refresh_minutes * 60 * 1000;
|
||||
let manager_refresh_time = manager_refresh_minutes * 60 * 1000;
|
||||
|
||||
// IDB caches - Check if the last refresh timestamp for $ae_loc.last_cache_refresh is no more than 15 minutes ago.
|
||||
let default_idb_refresh_time = 120 * 60 * 60 * 1000; // 15 minutes?
|
||||
let trusted_idb_refresh_time = 240 * 60 * 60 * 1000; // 4 hours or 120 minutes?
|
||||
let default_idb_refresh_time = 4 * 60 * 60 * 1000; // 15 minutes?
|
||||
let trusted_idb_refresh_time = 8 * 60 * 60 * 1000; // 4 hours or 120 minutes? 8 hours or 480 minutes?
|
||||
|
||||
if (!$ae_loc?.last_cache_refresh) { // Default is null, currently...
|
||||
console.log(`ROOT: Last reload not found. Need to set!`);
|
||||
@@ -302,22 +302,22 @@ if (!$ae_loc?.last_cache_refresh) { // Default is null, currently...
|
||||
flag_clear_idb = true;
|
||||
// flag_clear_local = false;
|
||||
// flag_clear_sess = false;
|
||||
flag_reload = true;
|
||||
flag_expired = true;
|
||||
// flag_reload = true;
|
||||
// flag_expired = true;
|
||||
|
||||
$ae_loc.cache_expired = true;
|
||||
$ae_loc.allow_access = false;
|
||||
// $ae_loc.cache_expired = true;
|
||||
// $ae_loc.allow_access = false;
|
||||
} else if (!$ae_loc?.trusted_access && (Date.now() - $ae_loc.last_cache_refresh) > default_idb_refresh_time) {
|
||||
console.log(`ROOT: Last (default) IDB reload too old for IDB: ${$ae_loc.last_cache_refresh}`);
|
||||
|
||||
flag_clear_idb = true;
|
||||
// flag_clear_local = false;
|
||||
// flag_clear_sess = false;
|
||||
flag_reload = true;
|
||||
flag_expired = true;
|
||||
// flag_reload = true;
|
||||
// flag_expired = true;
|
||||
|
||||
$ae_loc.cache_expired = true;
|
||||
$ae_loc.allow_access = false;
|
||||
// $ae_loc.cache_expired = true;
|
||||
// $ae_loc.allow_access = false;
|
||||
} else {
|
||||
if (log_lvl > 1) {
|
||||
console.log(`ROOT: Last IDB reload is recent: ${$ae_loc.last_cache_refresh}`);
|
||||
@@ -329,6 +329,22 @@ if (!$ae_loc?.last_cache_refresh) { // Default is null, currently...
|
||||
}
|
||||
// END: Expired Cache Check:
|
||||
|
||||
// $effect(() => {
|
||||
if (browser && flag_clear_idb) {
|
||||
if (log_lvl) {
|
||||
console.log(`ROOT: Clear IDB...`);
|
||||
}
|
||||
flag_clear_idb = false;
|
||||
$ae_loc.last_cache_refresh = Date.now();
|
||||
|
||||
clear_idb();
|
||||
|
||||
if (log_lvl) {
|
||||
console.log(`ROOT: IDB cleared. Reload!`);
|
||||
}
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
|
||||
// BEGIN: Access Checks:
|
||||
// Updated 2024-11-21
|
||||
@@ -371,50 +387,12 @@ if ($ae_loc?.site_cfg_json?.theme_mode) {
|
||||
$ae_loc.theme_mode = $ae_loc.site_cfg_json.theme_mode;
|
||||
}
|
||||
|
||||
// BEGIN: iframe Check:
|
||||
|
||||
// END: iframe Check:
|
||||
|
||||
|
||||
// BEGIN: Special Checks for Events, Sponsorships, IDAA, CHOW, etc.:
|
||||
// There should almost always be an event_id set.
|
||||
// if ($ae_loc?.site_cfg_json?.slct__event_id) {
|
||||
// $events_slct.event_id = $ae_loc.site_cfg_json.slct__event_id;
|
||||
// $events_loc.event_id = $ae_loc.site_cfg_json.slct__event_id;
|
||||
// } else if ($events_slct?.event_id) {
|
||||
// // console.log(`Event ID already set:`, $events_slct.event_id);
|
||||
// $events_loc.event_id = $events_slct.event_id;
|
||||
// } else {
|
||||
// if (log_lvl > 1) {
|
||||
// console.log(`No Event ID set!`);
|
||||
// }
|
||||
// }
|
||||
|
||||
// // This is mainly for Precon CHOW
|
||||
// if ($ae_loc?.site_cfg_json?.slct__sponsorship_cfg_id) {
|
||||
// $slct.sponsorship_cfg_id = $ae_loc.site_cfg_json.slct__sponsorship_cfg_id;
|
||||
// if ($ae_loc?.mod?.sponsorships) {
|
||||
// $ae_loc.mod.sponsorships.cfg_id = $ae_loc.site_cfg_json.slct__sponsorship_cfg_id;
|
||||
// } else {
|
||||
// $ae_loc.mod = {
|
||||
// ...$ae_loc.mod,
|
||||
// sponsorships: {
|
||||
// cfg_id: $ae_loc.site_cfg_json.slct__sponsorship_cfg_id
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
// } else if ($ae_loc?.sponsorship_cfg_id) {
|
||||
// $slct.sponsorship_cfg_id = $ae_loc.sponsorship_cfg_id;
|
||||
// $ae_loc.mod.sponsorships.cfg_id = $ae_loc.sponsorship_cfg_id;
|
||||
// } else {
|
||||
// if (log_lvl > 1) {
|
||||
// console.log(`No Sponsorship Config ID set.`);
|
||||
// }
|
||||
// }
|
||||
// BEGIN: Special Checks for Events, Sponsorships, IDAA, CHOW, LCI, etc.:
|
||||
// // END: Special Checks
|
||||
|
||||
// Root Svelte Layout Specific:
|
||||
let trigger_clear_access: null|boolean = $state(null);
|
||||
// let trigger_clear_access: null|boolean = $state(null);
|
||||
|
||||
if (browser) {
|
||||
document.documentElement.setAttribute('data-theme', $ae_loc?.theme_name ?? 'nouveau');
|
||||
@@ -427,14 +405,14 @@ if (browser && flag_reload) {
|
||||
console.log(`ROOT: Reloading page after other flags checked...`);
|
||||
}
|
||||
|
||||
// Clear Indexed DB as well
|
||||
if (flag_clear_idb) {
|
||||
if (log_lvl) {
|
||||
console.log(`ROOT: Clearing IndexedDB databases...`);
|
||||
}
|
||||
// // Clear Indexed DB as well
|
||||
// if (flag_clear_idb) {
|
||||
// if (log_lvl) {
|
||||
// console.log(`ROOT: Clearing IndexedDB databases...`);
|
||||
// }
|
||||
|
||||
clear_idb();
|
||||
}
|
||||
// clear_idb();
|
||||
// }
|
||||
|
||||
// Clear localStorage and sessionStorage
|
||||
if (flag_clear_local) {
|
||||
@@ -629,7 +607,7 @@ $effect(() => {
|
||||
}
|
||||
});
|
||||
|
||||
//
|
||||
|
||||
$effect(() => {
|
||||
if (browser) {
|
||||
const interval = setInterval(() => {
|
||||
@@ -831,21 +809,6 @@ $effect(() => {
|
||||
if (!confirm('Are you sure you want to clear the local and session storage?')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// // Clear the local and session storage
|
||||
// localStorage.clear();
|
||||
// sessionStorage.clear();
|
||||
|
||||
// // Clear Indexed DB as well
|
||||
// indexedDB.deleteDatabase('ae_core_db');
|
||||
// indexedDB.deleteDatabase('ae_archives_db');
|
||||
// indexedDB.deleteDatabase('ae_events_db');
|
||||
// indexedDB.deleteDatabase('ae_posts_db');
|
||||
|
||||
// window.location.reload();
|
||||
// // alert('Local and Session Storage cleared and Indexed DBs deleted. You will probably want to refresh the page.');
|
||||
|
||||
console.log('Reloading page...');
|
||||
// Clear the IndexedDB
|
||||
clear_idb();
|
||||
|
||||
@@ -975,7 +938,13 @@ email = ${$ae_loc?.email}
|
||||
onclick={() => {
|
||||
window.location.reload();
|
||||
}}
|
||||
class="btn btn-sm m-1 preset-tonal-surface border border-surface-500 hover:preset-tonal-warning border border-warning-500 hover:variant-outline-warning text-warning-800 hover:text-warning-900 transition-all"
|
||||
class="
|
||||
btn btn-sm m-1
|
||||
preset-tonal-surface border-surface-500
|
||||
hover:preset-tonal-warning hover:border-warning-500 hover:preset-outlined-warning
|
||||
text-warning-800 hover:text-warning-900
|
||||
transition-all
|
||||
"
|
||||
>
|
||||
<!-- <span class="fas fa-sync mx-1"></span> -->
|
||||
<RefreshCw class="mx-1" />
|
||||
|
||||
Reference in New Issue
Block a user