Commit b92b8120 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis
Browse files

Simplify query to avoid hitting db stack limit

Refs #3479

Looking up (entity, resource) pairs created a huge query formula
in disjunctive normal form, which apparently brought the db parser
to its limits.

It has been replaced by selecting the holdings by entity only.
This means that in theory we lock more holdings than needed (for any
resource for a given entity), but in practice we would need to
select these holdings anyway.
parent 4eee4823
......@@ -481,11 +481,9 @@ class QuotaholderDjangoDBCallpoint(Callpoint):
q_holdings = Q()
entities = []
for (entity, resource, key, _, _, _, _, _) in set_quota:
q_holdings |= Q(entity=entity, resource=resource)
entities.append(entity)
hs = Holding.objects.filter(q_holdings).select_for_update()
hs = Holding.objects.filter(entity__in=entities).select_for_update()
holdings = {}
for h in hs:
holdings[(h.entity_id, h.resource)] = h
......@@ -554,11 +552,9 @@ class QuotaholderDjangoDBCallpoint(Callpoint):
q_holdings = Q()
entities = []
for (entity, resource, key, _, _, _, _) in sources:
q_holdings |= Q(entity=entity, resource=resource)
entities.append(entity)
hs = Holding.objects.filter(q_holdings).select_for_update()
hs = Holding.objects.filter(entity__in=entities).select_for_update()
holdings = {}
for h in hs:
holdings[(h.entity_id, h.resource)] = h
......
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