unread icon indicating copy to clipboard operation
unread copied to clipboard

ReadMark.readable_classes is nil until the first use

Open ishields opened this issue 5 years ago • 0 comments

I'm noticing in development ReadMark.readable_classes is nil. It's not till I made a related call that it got defined with User as a readable type.

ReadMark.readable_classes => nil
User.first.have_read?(Article.last)  => false
ReadMark.readable_classes => [Article(id: integer ... )]

This resulted in some different behavior in console/development than what I could expect in the actual app. For example in the console:

def setup_new_reader
        (ReadMark.readable_classes || []).each do |klass|
          klass.mark_as_read! :all, for: self
        end
end

would not initially do anything, until after the .have_read? call.

Should ReadMark.readable_classe be you need to setup in a config or something?

I think this may be related to eager loading in development. If Article is not loaded before a User is created (which can happen all the time in development), then this unintentional behavior will happen.

ishields avatar Mar 12 '20 19:03 ishields