Commit 5470313f authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

cyclades: Do not prefetch related in get()

parent 1ad655cd
...@@ -164,7 +164,7 @@ def create_subnet(request): ...@@ -164,7 +164,7 @@ def create_subnet(request):
def get_subnet(request, sub_id): def get_subnet(request, sub_id):
"""Show info of a specific subnet""" """Show info of a specific subnet"""
user_id = request.user_uniq user_id = request.user_uniq
subnet = subnets.get_subnet(sub_id, prefetch_related=True) subnet = subnets.get_subnet(sub_id)
if (subnet.network.userid != user_id) and (subnet.network.public is False): if (subnet.network.userid != user_id) and (subnet.network.public is False):
raise api.faults.Unauthorized("You're not allowed to view this subnet") raise api.faults.Unauthorized("You're not allowed to view this subnet")
......
...@@ -222,7 +222,7 @@ def get_network(network_id, user_id, for_update=False, non_deleted=False): ...@@ -222,7 +222,7 @@ def get_network(network_id, user_id, for_update=False, non_deleted=False):
try: try:
network_id = int(network_id) network_id = int(network_id)
objects = Network.objects.prefetch_related("subnets") objects = Network.objects
if for_update: if for_update:
objects = objects.select_for_update() objects = objects.select_for_update()
network = objects.get(Q(userid=user_id) | Q(public=True), network = objects.get(Q(userid=user_id) | Q(public=True),
......
...@@ -148,14 +148,11 @@ def _create_subnet(network_id, user_id, cidr, name, ipversion=4, gateway=None, ...@@ -148,14 +148,11 @@ def _create_subnet(network_id, user_id, cidr, name, ipversion=4, gateway=None,
return sub return sub
def get_subnet(sub_id, prefetch_related=False): def get_subnet(sub_id):
"""Show info of a specific subnet""" """Show info of a specific subnet"""
log.debug('get_subnet %s', sub_id) log.debug('get_subnet %s', sub_id)
try: try:
subnets = Subnet.objects subnets = Subnet.objects
if prefetch_related:
subnets = subnets.select_related("network")
subnets = subnets.prefetch_related("ip_pools")
return subnets.get(id=sub_id) return subnets.get(id=sub_id)
except Subnet.DoesNotExist: except Subnet.DoesNotExist:
raise api.faults.ItemNotFound("Subnet not found") raise api.faults.ItemNotFound("Subnet not found")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment