-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
in-persistence attribute of unread boolean #19
Comments
In the controller: @messages = Message.with_read_marks_for(current_user) In the view: - @messages.each do |message|
- if message.unread?(current_user)
= content_tag :strong, message.subject
- else
= message.subject Hope this helps. |
I don't think it behave right. I am using PostgreSql. irb(main):004:0> Ticket.with_read_marks_for(u).first.unread?(u) In the case it is ture, it queries the database twice. One for the list of readables and one for the read_marks. I have a pull request. Please ignore it if I am wrong. Thanks. |
Yes, the database has to be touched twice in some cases. Please have a look at the code: Here is another example. You will see that the executed queries are optimized: n = 10
Message.with_read_marks_for(user).last(n).map { |message| message.unread?(user) } For this, only 2 queries are needed, not Your PR #20 looks interesting, though. Maybe the 2 queries can be combined into a single one. I will check it. |
Was looking at this method but behaved not as expected:
messages = Message.with_read_marks_for(current_user)
I was thinking if a method called with_unread_attr_for(reader) that would return all a list of readables with boolean attribute value indicating if it is unread by the reader. This might save us making additional calls to database to get the unread status of a list of readables.
Or am I missing something?
The text was updated successfully, but these errors were encountered: