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

quotaholder: Lock holdings in a single query

Order by primary key when selecting multiple holdings for update;
this most probably ensures that locking will happen in that order.

As per commit 2f90645, we select all holdings for the given holders,
rather that specifying all tuples (holder, source, resource), in order
to avoid query explosion.
parent da3216be
......@@ -69,15 +69,15 @@ def get_quota(holders=None, sources=None, resources=None):
def _get_holdings_for_update(holding_keys):
holding_keys = sorted(holding_keys)
holders = set(holder for (holder, source, resource) in holding_keys)
objs = Holding.objects
hs = objs.filter(holder__in=holders).order_by('pk').select_for_update()
holdings = {}
for (holder, source, resource) in holding_keys:
h = Holding.objects.get_for_update(
holder=holder, source=source, resource=resource)
holdings[(holder, source, resource)] = h
except Holding.DoesNotExist:
for h in hs:
key = h.holder, h.source, h.resource
holdings[key] = h
return holdings
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