sequenced
sequenced copied to clipboard
Suggestions/Questions
I had an idea for a similar gem in my TODO list, but after this week's RubyWeekly I noticed there is one already. So I will invest some effort into improving it, if you don't mind 😄
- Wdyt on supporting
scope
s asbelongs_to
association names:
class Answer < ActiveRecord::Base
belongs_to :question
acts_as_sequenced scope: :question
end
It looks more natural to me, than specifying column names and simplifies the setup when belongs_to
is polymorphic.
- Support sharing scopes. For example, like on GitHub: both issues and pull requests are scoped to a repository.
- Why testing of MySQL was removed from this gem?
- Currently, when calculating the next sequential id, the whole table is locked (PostgreSQL only 🤔?) https://github.com/derrickreimer/sequenced/blob/2c279c03a9950bccab0e7f4ca49bbfeb6f6317c5/lib/sequenced/generator.rb#L52-L56
Whole table locks are very heavyweight and dangerous (see lock queueing in PostgreSQL) and are really not needed. I suggest locking only the parent record (if
:scope
is for parent record) usingSELECT ... FOR UPDATE
(https://api.rubyonrails.org/v5.2/classes/ActiveRecord/Locking/Pessimistic.html), this should be enough. - README states that the
scope
option can be any attribute (not only the foreign key of an associated parent object). But what is the use case for this?
If these changes are OK, I will start implementing them one by one.