related_tag_calculator.rb: fix memcache lookup in inner loop.

Remove the category constraint option from RelatedTagCalculator.calculate_from_posts.
It slows things down and isn't used.

This method is used to calculate the related tags sidebar during
searches for single metatags. Using Tag.category_for in the inner loop
caused a memcache call on every iteration. At 100 posts per page and
20-30 tags per post, this led to up to 2000-3000 total memcache calls,
which significantly slowed pageloads.
This commit is contained in:
evazion
2017-04-23 13:35:18 -05:00
parent 76eefd0ffe
commit 8404064854
3 changed files with 13 additions and 19 deletions

View File

@@ -1,11 +1,14 @@
module PostSetPresenters
class Post < Base
attr_accessor :post_set, :tag_set_presenter
attr_accessor :post_set
delegate :posts, :to => :post_set
def initialize(post_set)
@post_set = post_set
@tag_set_presenter = TagSetPresenter.new(related_tags)
end
def tag_set_presenter
@tag_set_presenter ||= TagSetPresenter.new(related_tags)
end
def related_tags
@@ -51,7 +54,7 @@ module PostSetPresenters
end
def calculate_related_tags_from_post_set
RelatedTagCalculator.calculate_from_post_set_to_array(post_set).map(&:first)
RelatedTagCalculator.calculate_from_posts_to_array(post_set.posts).map(&:first)
end
def saved_search_labels