sequenced icon indicating copy to clipboard operation
sequenced copied to clipboard

Suggestions/Questions

Open fatkodima opened this issue 2 years ago • 0 comments

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 😄

  1. Wdyt on supporting scopes as belongs_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.

  1. Support sharing scopes. For example, like on GitHub: both issues and pull requests are scoped to a repository.
  2. Why testing of MySQL was removed from this gem?
  3. 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) using SELECT ... FOR UPDATE (https://api.rubyonrails.org/v5.2/classes/ActiveRecord/Locking/Pessimistic.html), this should be enough.
  4. 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.

fatkodima avatar Aug 26 '22 20:08 fatkodima