From 4e10dab5a877d966501c94d24aca38404878178c Mon Sep 17 00:00:00 2001 From: Araxeus <78568641+Araxeus@users.noreply.github.com> Date: Mon, 27 Mar 2023 22:25:57 +0300 Subject: [PATCH] cache downloader `getCoverBuffer()` --- plugins/downloader/back.js | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/plugins/downloader/back.js b/plugins/downloader/back.js index 6263930b..5d1f03b2 100644 --- a/plugins/downloader/back.js +++ b/plugins/downloader/back.js @@ -10,6 +10,7 @@ const { fetchFromGenius } = require('../lyrics-genius/back'); const { isEnabled } = require('../../config/plugins'); const { getImage } = require('../../providers/song-info'); const { injectCSS } = require('../utils'); +const { cache } = require("../../providers/decorators") const { presets, cropMaxWidth, @@ -34,13 +35,6 @@ const ffmpeg = require('@ffmpeg/ffmpeg').createFFmpeg({ }); const ffmpegMutex = new Mutex(); -const cache = { - getCoverBuffer: { - buffer: null, - url: null, - }, -}; - const config = require('./config'); /** @type {Innertube} */ @@ -295,19 +289,10 @@ async function iterableStreamToMP3( } } -async function getCoverBuffer(url) { - const store = cache.getCoverBuffer; - if (store.url === url) { - return store.buffer; - } - store.url = url; - +const getCoverBuffer = cache(async (url) => { const nativeImage = cropMaxWidth(await getImage(url)); - store.buffer = - nativeImage && !nativeImage.isEmpty() ? nativeImage.toPNG() : null; - - return store.buffer; -} + return nativeImage && !nativeImage.isEmpty() ? nativeImage.toPNG() : null; +}); async function writeID3(buffer, metadata, sendFeedback) { try {