From d3362604b50467d7d78a0bb040eb86d3ee60662b Mon Sep 17 00:00:00 2001 From: Rolando Santamaria Maso Date: Wed, 20 Sep 2023 08:29:23 +0200 Subject: [PATCH] refactoring for enhanced code readability --- utils.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/utils.js b/utils.js index 0a6b194..eb49662 100644 --- a/utils.js +++ b/utils.js @@ -18,18 +18,9 @@ const getKeys = (cache, pattern) => new Promise((resolve) => { const get = (cache, key) => cache.getAndPassUp(key) const deleteKeys = (stores, patterns) => { - patterns = patterns.map(pattern => pattern.endsWith('*') - ? pattern - : [pattern, pattern + DATA_POSTFIX] - ).reduce((acc, item) => { - if (Array.isArray(item)) { - acc.push(...item) - } else { - acc.push(item) - } - - return acc - }, []) + patterns = patterns.map(pattern => + pattern.endsWith('*') ? pattern : [pattern, pattern + DATA_POSTFIX] + ).flat() patterns.forEach(pattern => stores.forEach(store => getKeys(store, pattern).then(keys => keys.length > 0 ? store.del(keys) : null))) }