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

@@ -20,3 +20,4 @@ gem "mechanize"
gem "nokogiri"
gem "meta_search", :git => "git://github.com/ernie/meta_search.git"
gem "silent-postgres"
gem "whenever", :require => false

View File

@@ -16,6 +16,7 @@ GIT
GEM
remote: http://gemcutter.org/
specs:
aaronh-chronic (0.3.9)
actionmailer (3.1.0.rc1)
actionpack (= 3.1.0.rc1)
mail (~> 2.3.0)
@@ -124,6 +125,9 @@ GEM
tzinfo (0.3.29)
webrobots (0.0.10)
nokogiri (>= 1.4.4)
whenever (0.6.8)
aaronh-chronic (>= 0.3.9)
activesupport (>= 2.3.4)
PLATFORMS
ruby
@@ -146,3 +150,4 @@ DEPENDENCIES
simple_form
simplecov
super_exception_notifier
whenever

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

5
config/schedule.rb Normal file
View File

@@ -0,0 +1,5 @@
set :output, "/var/log/whenever.log"
every 1.hour do
TagSubscription.process_all
end

View File

@@ -525,7 +525,13 @@ class PostTest < ActiveSupport::TestCase
assert_equal(post2.id, relation.first.id)
end
should "return posts for a tag subscription search"
should "return posts for a tag subscription search" do
post1 = Factory.create(:post, :tag_string => "aaa")
sub = Factory.create(:tag_subscription, :tag_query => "aaa", :name => "zzz")
TagSubscription.process_all
relation = Post.tag_match("sub:#{CurrentUser.name}")
assert_equal(1, relation.count)
end
should "return posts for a particular rating" do
post1 = Factory.create(:post, :rating => "s")

View File

@@ -6,6 +6,7 @@ class TagTest < ActiveSupport::TestCase
CurrentUser.user = user
CurrentUser.ip_addr = "127.0.0.1"
MEMCACHE.flush_all
Delayed::Worker.delay_jobs = false
end
teardown do

BIN
tmp/test.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB