When retrieving unread entries, we already know that all entries in the list will be unread (it is guaranteed by the queries that get them from the DB). Therefore the step of looking at entry_states table for each entry to find out its read/unread state can be safely skipped. This saves one SQL GET and instantiating an ActiveRecord object for each entry in the list.
This does not apply when retrieving all entries, both read and unread. In this case we don't know each entry state beforehand, so it must be retrieved from the DB. Probably some kind of optimization could be applied here in the future, either database denormalization or eager loading of the state.
↧