Files
ubicloud/lib/sem_snap.rb
Jeremy Evans 106a52cbef Make Semaphore.incr use a single query
Previously, it would usually use 2 queries if inside a transaction,
or 4 queries if outside a transaction.  This replaces the UPDATE
then INSERT query approach with an INSERT SELECT (UPDATE RETURNING)
approach in a single query.  As this is a single query and not
multiple queries, it does not need a transaction.  If the UPDATE
does not update a row, then no rows will be inserted.

This approach also opens up the ability to create multiple
semaphores in a single query, if the first argument is an array
or a dataset.  That will be used in an upcoming commit.

This changes the return value of Semaphore.incr when provided
a single id from returning a Semaphore instance to returning
the Semaphore uuid.  Only SemSnap#incr cares about the return
value, so update that to fetch the Semaphore.
2025-06-04 05:26:37 +09:00

1.1 KiB