-
Preload the comment_thread relation before serializing comments. · 08521b98
When a single thread is presented/serialized, it loads all of the comments for that thread, or whatever ones fall in the pagination range, and serializes them by calling #to_hash before shoving them into an array. When calling #to_hash on a comment, the comment has to look at its parent thread to get some information, which requires loading that comment thread lazily and creating the Ruby object for it, etc. This is an experiment is trying to use Criteria#includes to preload it instead of letting it be lazily loaded, to see if it can do more of the work upfront leading to less work needing to happen when lazily loaded. The database isn't being queried every time right now, but I have an assumption that it's simply creating new comment thread objects based on the cached MongoDB results, and that preloading might actually only create those objects once (because they all share the same parent) and then assign it to every comment, effectively making it a one-time thing vs an N-time thing. This might be totally off: I still need to profile this to see what's going on precisely. All I know is that serializing a single comment can take 10s of milliseconds, which is really slow for what ought to be simply taking a Mongoid document and making it a hash.
Toby Lawrence committed
Name |
Last commit
|
Last update |
---|---|---|
.. | ||
thread.rb | Loading commit data... | |
thread_list.rb | Loading commit data... | |
thread_utils.rb | Loading commit data... |