added whenever (cron replacement), fixed related tag calculation updates (now delayed), tag subscriptions now calculated on cron

This commit is contained in:
albert
2011-08-05 19:07:28 -04:00
parent e106f70b6d
commit c078178fc4
8 changed files with 33 additions and 11 deletions

View File

@@ -488,16 +488,20 @@ class Post < ActiveRecord::Base
def add_tag_subscription_relation(subscriptions, relation)
subscriptions.each do |subscription|
subscription =~ /^(.+?):(.+)$/
user_name = $1 || subscription
subscription_name = $2
user = User.find_by_name(user_name)
if user
if subscription =~ /^(.+?):(.+)$/
user_name = $1
subscription_name = $2
user = User.find_by_name(user_name)
return relation if user.nil?
post_ids = TagSubscription.find_post_ids(user.id, subscription_name)
relation = relation.where(["posts.id IN (?)", post_ids])
else
user = User.find_by_name(subscription)
return relation if user.nil?
post_ids = TagSubscription.find_post_ids(user.id)
end
post_ids = [0] if post_ids.empty?
relation = relation.where(["posts.id IN (?)", post_ids])
end
relation

View File

@@ -310,11 +310,11 @@ class Tag < ActiveRecord::Base
module RelationMethods
def update_related
counts = RelatedTagCalculator.calculate_from_sample(Danbooru.config.post_sample_size, name)
self.related_tags = RelatedTagCalculator.convert_hash_to_string(counts)
update_attributes(:related_tags => RelatedTagCalculator.convert_hash_to_string(counts), :related_tags_updated_at => Time.now)
end
def update_related_if_outdated
updated_related if should_update_related?
delay.update_related if should_update_related?
end
def related_cache_expiry