Skip to content

Sort On Demand #328

@josephwegner

Description

@josephwegner

Right now, when you load the homepage (or any subsequent news page), here's what happens:

  1. The 900 most recent news items are grabbed from the database (mongoose also populates the "poster" field in this process)
  2. The votes for all of those posts are retrieved from the database (inefficient "in" query)
  3. 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).
  4. A score is calculated for each post (900 iterations)
  5. The posts are sorted by score (this is most likely not an efficient sorting algorithm)
  6. The list is trimmed down to the 30 relevant entries
  7. The comments are added to each post (30 separate queries)
  8. The latest comment is added to each post (30 separate queries)
  9. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions