Merge pull request #3092 from evazion/opt-reltags

Optimize related tags calculation
This commit is contained in:
Albert Yi
2017-05-30 11:12:24 -07:00
committed by GitHub
2 changed files with 21 additions and 24 deletions

View File

@@ -1593,6 +1593,17 @@ class Post < ActiveRecord::Base
where("md5 >= ?", key).reorder("md5 asc").first
end
def sample(query, sample_size)
CurrentUser.without_safe_mode do
tag_match(query).reorder(:md5).limit(sample_size)
end
end
# unflattens the tag_string into one tag per row.
def with_unflattened_tags
joins("CROSS JOIN unnest(string_to_array(tag_string, ' ')) AS tag")
end
def pending
where("is_pending = ?", true)
end