mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-09 11:46:49 +00:00
perf(instances): a user's VM list reads only the hosts of their VMs
The list page synchronised and connected to every compute for every user, while the poll and the API list read only the hosts of the user's own VMs. Hosts a user has no VMs on no longer get a listing per page load, which also took one of their request slots.
This commit is contained in:
parent
f3c44f18c4
commit
fe102f98c8
2 changed files with 17 additions and 3 deletions
|
|
@ -68,3 +68,17 @@ class IndexHostAlertTests(TestCase):
|
|||
response = self.get(viewer, down=set())
|
||||
self.assertContains(response, "mine-host")
|
||||
self.assertNotContains(response, reverse("overview", args=[self.mine.id]))
|
||||
|
||||
def test_a_users_list_reads_only_the_hosts_of_their_vms(self):
|
||||
read = []
|
||||
|
||||
def status(compute):
|
||||
read.append(compute.name)
|
||||
return True
|
||||
|
||||
self.client.force_login(self.user)
|
||||
with patch("instances.views.utils.refr") as refr, patch.object(Compute, "status", property(status)), \
|
||||
patch.object(Instance, "info", new_callable=PropertyMock, return_value=None):
|
||||
self.assertEqual(self.client.get(reverse("instances:index")).status_code, 200)
|
||||
self.assertEqual([call.args[0].name for call in refr.call_args_list], ["mine-host"])
|
||||
self.assertNotIn("other-host", read)
|
||||
|
|
|
|||
|
|
@ -79,7 +79,8 @@ STATS_SAMPLE_SIGNER = signing.TimestampSigner(salt="instances.stats-sample")
|
|||
def index(request):
|
||||
instances = None
|
||||
|
||||
computes = list(Compute.objects.all().order_by("name"))
|
||||
# a user who sees no hosts makes the panel read only those of their own VMs
|
||||
computes = _listed_computes(request.user, list(Compute.objects.all().order_by("name")))
|
||||
for compute in computes:
|
||||
utils.refr(compute)
|
||||
|
||||
|
|
@ -98,8 +99,7 @@ def index(request):
|
|||
).order_by("name").prefetch_related("userinstance_set__user"))
|
||||
# other users get no host names or connection errors, only whether
|
||||
# a host of their own VMs is down
|
||||
own = {inst.compute_id for inst in instances}
|
||||
own_hosts_down = any(c.status is not True for c in computes if c.pk in own)
|
||||
own_hosts_down = any(c.status is not True for c in computes)
|
||||
utils.read_list_rows(instances)
|
||||
|
||||
return render(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue