Explorar o código

fix: adjust lyrics cache size

Sv443 hai 1 ano
pai
achega
c861e9d331
Modificáronse 2 ficheiros con 14 adicións e 5 borrados
  1. 1 1
      changelog.md
  2. 13 4
      src/features/lyrics.ts

+ 1 - 1
changelog.md

@@ -1,6 +1,6 @@
 ## 1.2.0
 - **Features / Changes:**
-  - Added a persistent cache to save lyrics in. Up to 1000 of the most listened to songs are cached throughout sessions for 30 days to save time and reduce server load.
+  - Added a persistent cache to save lyrics in. Up to 500 of the most listened to songs are cached throughout sessions for 3 weeks to save time and reduce server load.
   - Added filtering algorithm to lyrics fetching to yield more accurate results
   - Improved accessibility of hotkey inputs
   - Remade the toggle buttons in the config menu to look cool and still be just as accessible

+ 13 - 4
src/features/lyrics.ts

@@ -15,9 +15,9 @@ const geniUrlRatelimitTimeframe = 30;
 //#MARKER new cache
 
 /** How many cache entries can exist at a time - this is used to cap memory usage */
-const maxLyricsCacheSize = 1000;
+const maxLyricsCacheSize = 500;
 /** Maximum time before a cache entry is force deleted */
-const cacheTTL = 1000 * 60 * 60 * 24 * 30; // 30 days
+const cacheTTL = 1000 * 60 * 60 * 24 * 21; // 21 days
 
 export type LyricsCache = {
   cache: LyricsCacheEntry[];
@@ -252,6 +252,15 @@ export function sanitizeArtists(artists: string) {
   if(artists.match(/,/))
     artists = artists.split(/,\s*/gm)[0];
 
+  if(artists.match(/(f(ea)?t\.?|Remix|Edit|Flip|Cover|Night\s?Core|Bass\s?Boost|pro?d\.?)/i)) {
+    const parensRegex = /\(.+\)/gmi;
+    const squareParensRegex = /\[.+\]/gmi;
+
+    artists = artists
+      .replace(parensRegex, "")
+      .replace(squareParensRegex, "");
+  }
+
   return artists.trim();
 }
 
@@ -435,9 +444,9 @@ export async function fetchLyricsUrls(artist: string, song: string): Promise<Omi
       ),
     ].slice(0, 5);
 
-    // add results to the cache with a penalty to their time to live
+    // add top 3 results to the cache with a penalty to their time to live
     // so every entry is deleted faster if it's not considered as relevant
-    finalResults.forEach(({ meta: { artists, title }, url }, i) => {
+    finalResults.slice(1, 3).forEach(({ meta: { artists, title }, url }, i) => {
       const penaltyFraction = hasExactMatch
         // if there's an exact match, give it 0 penalty and penalize all other results with the full value
         ? i === 0 ? 0 : 1