feat(xo-server/sr.getAllUnhealthyVdiChainsLength): memoize 60 seconds
Introduced by 0975863d9
This commit is contained in:
@@ -27,3 +27,5 @@
|
||||
> - major: if the change breaks compatibility
|
||||
>
|
||||
> In case of conflict, the highest (lowest in previous list) `$version` wins.
|
||||
|
||||
- xo-server patch
|
||||
|
||||
@@ -39,7 +39,12 @@ export const debounceWithKey = (fn, delay, keyFn = defaultKeyFn) => {
|
||||
const keys = ensureArray(keyFn.apply(this, arguments))
|
||||
let promise = cache.get(keys)
|
||||
if (promise === undefined) {
|
||||
cache.set(keys, (promise = fn.apply(this, arguments)))
|
||||
cache.set(
|
||||
keys,
|
||||
(promise = new Promise(resolve => {
|
||||
resolve(fn.apply(this, arguments))
|
||||
}))
|
||||
)
|
||||
const remove = scheduleRemoveCacheEntry.bind(cache, keys, Date.now() + delayFn.apply(this, arguments))
|
||||
promise.then(remove, remove)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import some from 'lodash/some.js'
|
||||
|
||||
import ensureArray from '../_ensureArray.mjs'
|
||||
import { asInteger } from '../xapi/utils.mjs'
|
||||
import { debounceWithKey } from '../_pDebounceWithKey.mjs'
|
||||
import { forEach, parseXml } from '../utils.mjs'
|
||||
|
||||
// ===================================================================
|
||||
@@ -866,7 +867,7 @@ probeNfsExists.resolve = {
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export function getAllUnhealthyVdiChainsLength() {
|
||||
export const getAllUnhealthyVdiChainsLength = debounceWithKey(function getAllUnhealthyVdiChainsLength() {
|
||||
const unhealthyVdiChainsLengthBySr = {}
|
||||
filter(this.objects.all, obj => obj.type === 'SR' && obj.content_type !== 'iso' && obj.size > 0).forEach(sr => {
|
||||
const unhealthyVdiChainsLengthByVdi = this.getXapi(sr).getUnhealthyVdiChainsLength(sr)
|
||||
@@ -875,7 +876,7 @@ export function getAllUnhealthyVdiChainsLength() {
|
||||
}
|
||||
})
|
||||
return unhealthyVdiChainsLengthBySr
|
||||
}
|
||||
}, 60e3)
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user