Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(xo-server/rest-api/dashboard): avoid iterating over all XAPI objects #8008

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 12 additions & 23 deletions packages/xo-server/src/xo-mixins/rest-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -174,34 +174,23 @@ async function _getDashboardStats(app) {
}
}

const poolIds = new Set()
const hosts = []
const writableSrs = []
const nonReplicaVms = []
const pools = Object.values(app.objects.indexes.type.pool)
const hosts = Object.values(app.objects.indexes.type.host)
const srs = Object.values(app.objects.indexes.type.SR)
const vms = Object.values(app.objects.indexes.type.VM)
Comment on lines +177 to +180
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful, any one of these entries can be undefined if there are no such objects of a given type.


const writableSrs = srs.filter(isSrWritable)
const nonReplicaVms = vms.filter(vm => !isReplicaVm(vm))
const vmIdsProtected = new Set()
const vmIdsUnprotected = new Set()

for (const obj of app.objects.values()) {
if (obj.type === 'host') {
hosts.push(obj)
poolIds.add(obj.$pool)
if (hvSupportedVersions !== undefined && !semver.satisfies(obj.version, hvSupportedVersions[obj.productBrand])) {
nHostsEol++
}
}

if (obj.type === 'SR') {
if (isSrWritable(obj)) {
writableSrs.push(obj)
}
}

if (obj.type === 'VM' && !isReplicaVm(obj)) {
nonReplicaVms.push(obj)
hosts.forEach(host => {
if (hvSupportedVersions !== undefined && !semver.satisfies(host.version, hvSupportedVersions[host.productBrand])) {
nHostsEol++
}
}
})

dashboard.nPools = poolIds.size
dashboard.nPools = pools.length
dashboard.nHosts = hosts.length
dashboard.nHostsEol = nHostsEol

Expand Down
2 changes: 2 additions & 0 deletions packages/xo-server/src/xo.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import stubTrue from 'lodash/stubTrue.js'
import SslCertificate from '@xen-orchestra/mixins/SslCertificate.mjs'
import Tasks from '@xen-orchestra/mixins/Tasks.mjs'
import { Collection as XoCollection } from 'xo-collection'
import { Index } from 'xo-collection/index.js'
import { createClient as createRedisClient } from 'redis'
import { createDebounceResource } from '@vates/disposable/debounceResource.js'
import { createLogger } from '@xen-orchestra/log'
Expand Down Expand Up @@ -41,6 +42,7 @@ export default class Xo extends EventEmitter {

this._objects = new XoCollection()
this._objects.createIndex('byRef', new XoUniqueIndex('_xapiRef'))
this._objects.createIndex('type', new Index('type'))

this._httpRequestWatchers = { __proto__: null }

Expand Down
Loading