-
Notifications
You must be signed in to change notification settings - Fork 81
Open
Description
Followup from #661
The proposal here is to fully adopt the code held in django_pglocks_advisory_lock
. That means that we would extract several parts of the logic into the new method:
elif isinstance(lock_id, str):
# Generates an id within postgres integer range (-2^31 to 2^31 - 1).
# crc32 generates an unsigned integer in Py3, we convert it into
# a signed integer using 2's complement (this is a noop in Py2)
pos = crc32(lock_id.encode("utf-8"))
lock_id = (2**31 - 1) & pos
if pos & 2**31:
lock_id -= 2**31
We would put this in a new method, takes a string, returns an integer. Also, very interesting for debugging, we could make a reverse method for debugging, so it takes an integer and returns the string that produced it? We could even have a method that returned a list of all the locks being held, maybe?
Next, we should change the import of from django.db connections
to the more direct from django.db.transaction import get_connection
Metadata
Metadata
Assignees
Labels
No labels