1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-10 20:26:48 +00:00

perf(instances): a VM list reads only the VMs it shows

#394 read each host's states in one call and every domain's XML once,
for the title, memory and vCPUs. A user's list shows only their own VMs,
but it read the XML of every VM on those hosts: a user with two VMs on a
host of 300 made about 301 libvirt calls a list load, where the old
per-VM reads made 6.

get_domain_rows takes the UUIDs the list shows and reads only their XML;
the states still come in one call. The capacity reads every domain, as
before.
This commit is contained in:
catborise 2026-11-04 23:58:36 +03:00
parent 02d4d02757
commit 337063bf7b
5 changed files with 28 additions and 11 deletions

View file

@ -356,10 +356,12 @@ def read_list_rows(instances):
"""Each VM's info and title for a VM list, read once a host
(get_domain_rows), not three calls a VM; a VM whose host or whose
domain cannot be read has no info: the list shows it unknown."""
rows = {}
rows, shown = {}, {}
for inst in instances:
shown.setdefault(inst.compute_id, set()).add(inst.uuid)
for compute in {inst.compute_id: inst.compute for inst in instances}.values():
try:
rows[compute.pk] = compute.proxy.get_domain_rows() if compute.status is True else {}
rows[compute.pk] = compute.proxy.get_domain_rows(shown[compute.pk]) if compute.status is True else {}
except libvirtError:
rows[compute.pk] = {}
for inst in instances: