Skip to content

Commit

Permalink
refactoring for enhanced code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
jkyberneees committed Sep 20, 2023
1 parent bc7e6ac commit d336260
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
Expand Down

0 comments on commit d336260

Please sign in to comment.