Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2025
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. console.log("šŸ”„ Detecting missing teamSeasons and loading them into the cache...");
  2.  
  3. // Fetch all teamSeasons currently in cache
  4. const cachedTeamSeasons = await bbgm.idb.cache.teamSeasons.getAll();
  5. const cachedSeasons = new Set(cachedTeamSeasons.map(ts => ts.season));
  6.  
  7. // Identify available seasons in IndexedDB by fetching them one by one
  8. const allSeasons = new Set();
  9. for (let year = 2020; year <= bbgm.g.get("season"); year++) { // Adjust 2020 to earliest possible season
  10. const seasonEntries = await bbgm.idb.getCopies.teamSeasons({ season: year });
  11.  
  12. if (seasonEntries.length > 0) {
  13. allSeasons.add(year);
  14. }
  15. }
  16.  
  17. console.log(`šŸ“… Seasons stored in IndexedDB: ${[...allSeasons].join(", ")}`);
  18. console.log(`šŸ“Œ Cached seasons: ${[...cachedSeasons].join(", ")}`);
  19.  
  20. // Identify missing seasons (not in cache but exist in IndexedDB)
  21. const missingSeasons = [...allSeasons].filter(season => !cachedSeasons.has(season));
  22.  
  23. if (missingSeasons.length === 0) {
  24. console.log("āœ… All teamSeasons are already loaded into the cache. No action needed.");
  25. } else {
  26. console.log(`āš ļø Missing seasons detected: ${missingSeasons.join(", ")}`);
  27. let addedToCache = 0;
  28.  
  29. for (const year of missingSeasons) {
  30. const seasonEntries = await bbgm.idb.getCopies.teamSeasons({ season: year });
  31.  
  32. if (seasonEntries.length > 0) {
  33. for (const entry of seasonEntries) {
  34. await bbgm.idb.cache.teamSeasons.put(entry);
  35. addedToCache++;
  36. }
  37. console.log(`āœ… Successfully added ${seasonEntries.length} entries for ${year} to cache.`);
  38. } else {
  39. console.log(`āš ļø No teamSeasons found for ${year}. Data may be lost.`);
  40. }
  41. }
  42.  
  43. console.log(`šŸŽÆ Total added entries to cache: ${addedToCache}`);
  44. }
  45.  
  46. // Re-fetch teamSeasons to verify update
  47. const updatedTeamSeasons = await bbgm.idb.cache.teamSeasons.getAll();
  48. const updatedSeasons = new Set(updatedTeamSeasons.map(ts => ts.season));
  49.  
  50. console.log("\nšŸ“Š Final Cached Seasons After Update:");
  51. console.log([...updatedSeasons].join(", "));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement