-
Notifications
You must be signed in to change notification settings - Fork 241
Open
Labels
Description
Right now, when you load the homepage (or any subsequent news page), here's what happens:
- The 900 most recent news items are grabbed from the database (mongoose also populates the "poster" field in this process)
- The votes for all of those posts are retrieved from the database (inefficient "in" query)
- For each post, the entire set of votes is iterated over and associated back to the post record (with an average of 2 votes per post, that's 1800 votes. So looping over 1800 votes for 900 posts means 1,620,000 iterations).
- A score is calculated for each post (900 iterations)
- The posts are sorted by score (this is most likely not an efficient sorting algorithm)
- The list is trimmed down to the 30 relevant entries
- The comments are added to each post (30 separate queries)
- The latest comment is added to each post (30 separate queries)
- The posts are passed off to the view to be rendered
As you can see, this is a terribly heavy process. We're not feeling the full weight of it yet, because we don't have 900 posts, but Pullup will continue to degrade in performance as we post more topics.
Along with some improvements on the scoring process, I suggest that we update the score on demand. Currently, posts will only change order based on two events: a new vote, or a new post. The score is calculated based on age, but all posts age at the same rate so the scores should age similarly. I think we should recalculate scores every time a vote is placed or a post is added, and store that value in the database.