Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- console.log("š Detecting missing teamSeasons and loading them into the cache...");
- // Fetch all teamSeasons currently in cache
- const cachedTeamSeasons = await bbgm.idb.cache.teamSeasons.getAll();
- const cachedSeasons = new Set(cachedTeamSeasons.map(ts => ts.season));
- // Identify available seasons in IndexedDB by fetching them one by one
- const allSeasons = new Set();
- for (let year = 2020; year <= bbgm.g.get("season"); year++) { // Adjust 2020 to earliest possible season
- const seasonEntries = await bbgm.idb.getCopies.teamSeasons({ season: year });
- if (seasonEntries.length > 0) {
- allSeasons.add(year);
- }
- }
- console.log(`š Seasons stored in IndexedDB: ${[...allSeasons].join(", ")}`);
- console.log(`š Cached seasons: ${[...cachedSeasons].join(", ")}`);
- // Identify missing seasons (not in cache but exist in IndexedDB)
- const missingSeasons = [...allSeasons].filter(season => !cachedSeasons.has(season));
- if (missingSeasons.length === 0) {
- console.log("ā All teamSeasons are already loaded into the cache. No action needed.");
- } else {
- console.log(`ā ļø Missing seasons detected: ${missingSeasons.join(", ")}`);
- let addedToCache = 0;
- for (const year of missingSeasons) {
- const seasonEntries = await bbgm.idb.getCopies.teamSeasons({ season: year });
- if (seasonEntries.length > 0) {
- for (const entry of seasonEntries) {
- await bbgm.idb.cache.teamSeasons.put(entry);
- addedToCache++;
- }
- console.log(`ā Successfully added ${seasonEntries.length} entries for ${year} to cache.`);
- } else {
- console.log(`ā ļø No teamSeasons found for ${year}. Data may be lost.`);
- }
- }
- console.log(`šÆ Total added entries to cache: ${addedToCache}`);
- }
- // Re-fetch teamSeasons to verify update
- const updatedTeamSeasons = await bbgm.idb.cache.teamSeasons.getAll();
- const updatedSeasons = new Set(updatedTeamSeasons.map(ts => ts.season));
- console.log("\nš Final Cached Seasons After Update:");
- console.log([...updatedSeasons].join(", "));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement