Skip to content

Commit

Permalink
Discuss the advisory lock in the README
Browse files Browse the repository at this point in the history
  • Loading branch information
brendon committed Mar 12, 2024
1 parent f77fd35 commit 9155852
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ item.update list: other_list, position: {after: 11}

It's important to note that in the examples above, `other_item` must already belong to the `other_list` scope.

## Concurrency

The queries that this gem runs, especially those that seek the next position integer available are vulnerable to race conditions. To this end, we've introduced an Advisory Lock to ensure that our model callbacks that determine and assign positions run sequentially. In short, an advisory lock prevents more than one process from running a particular block of code at the same time. The lock occurs in the database (or in the case of SQLite, on the filesystem), so as long as all of your processes are using the same database, the lock will prevent multiple positioning callbacks from executing on the same table and positioning column combination at the same time. You're encouraged to review the Advisory Lock code to ensure it fits with your environment:

https://github.com/brendon/positioning/blob/main/lib/positioning/advisory_lock.rb

If you have any concerns or improvements please file a GitHub issue.

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
Expand Down

0 comments on commit 9155852

Please sign in to comment.