diff --git a/app/controllers/legacy_controller.rb b/app/controllers/legacy_controller.rb index 799c2300f..9cc2dd955 100644 --- a/app/controllers/legacy_controller.rb +++ b/app/controllers/legacy_controller.rb @@ -17,7 +17,7 @@ class LegacyController < ApplicationController @upload.rating = params[:post][:rating][0].downcase @upload.md5_confirmation = params[:md5] if params[:md5].present? @upload.save - @upload.delay.process! + @upload.process! end def users diff --git a/app/models/post.rb b/app/models/post.rb index 280e9bc90..0ef65e300 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -622,6 +622,8 @@ class Post < ActiveRecord::Base if tags.blank? && Danbooru.config.blank_tag_search_fast_count count = Danbooru.config.blank_tag_search_fast_count + elsif tags =~ /^rating:\S+$/ + count = Danbooru.config.blank_tag_search_fast_count elsif tags =~ /(?:#{Tag::METATAGS}):/ count = fast_count_search(tags) else diff --git a/app/models/tag.rb b/app/models/tag.rb index 36bd83e8a..0bd709cda 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -81,17 +81,15 @@ class Tag < ActiveRecord::Base end def update_category_cache_for_all - Danbooru.config.all_server_hosts.each do |host| - delay.update_category_cache(host) + if category_changed? + Danbooru.config.all_server_hosts.each do |host| + delay(:queue => host).update_category_cache + end end end - def update_category_cache(host) - if host == Socket.gethostname - Cache.put("tc:#{Cache.sanitize(name)}", category, 1.hour) - else - delay.update_category_cache(host) - end + def update_category_cache + Cache.put("tc:#{Cache.sanitize(name)}", category, 1.hour) end end @@ -371,7 +369,13 @@ class Tag < ActiveRecord::Base end def update_related_if_outdated - delay.update_related if should_update_related? + if should_update_related? + if post_count < 100 + update_related + else + delay.update_related + end + end end def related_cache_expiry @@ -386,7 +390,7 @@ class Tag < ActiveRecord::Base end def should_update_related? - Delayed::Job.count < 200 && related_tags.blank? || related_tags_updated_at.blank? || related_tags_updated_at < related_cache_expiry.hours.ago + Delayed::Job.count < 200 && (related_tags.blank? || related_tags_updated_at.blank? || related_tags_updated_at < related_cache_expiry.hours.ago) end def related_tag_array diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index ce951df90..d8795cec1 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -88,16 +88,12 @@ class TagAlias < ActiveRecord::Base def clear_all_cache Danbooru.config.all_server_hosts.each do |host| - delay.clear_cache(host) + delay(:queue => host).clear_cache(host) end end def clear_cache(host = Socket.gethostname) - if host == Socket.gethostname - Cache.delete("ta:#{Cache.sanitize(antecedent_name)}") - else - delay.clear_cache(host) - end + Cache.delete("ta:#{Cache.sanitize(antecedent_name)}") end def update_cache diff --git a/app/models/upload.rb b/app/models/upload.rb index 8dba98c48..489f968ba 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -12,7 +12,7 @@ class Upload < ActiveRecord::Base before_create :convert_cgi_file after_destroy :delete_temp_file validate :uploader_is_not_limited - validate :file_or_source_is_present + validate :file_or_source_is_present, :on => :create module ValidationMethods def uploader_is_not_limited @@ -65,11 +65,6 @@ class Upload < ActiveRecord::Base def process! force=false return if !force && status =~ /processing|completed|error/ - if server != Socket.gethostname - delay.process! - return - end - CurrentUser.scoped(uploader, uploader_ip_addr) do update_attribute(:status, "processing") if is_downloadable? diff --git a/config/danbooru_default_config.rb b/config/danbooru_default_config.rb index 8b4116927..e19fa2c49 100644 --- a/config/danbooru_default_config.rb +++ b/config/danbooru_default_config.rb @@ -168,7 +168,7 @@ module Danbooru # Names of other Danbooru servers. def other_server_hosts - all_server_hosts.reject {|x| x == server_host} + @other_server_hosts ||= all_server_hosts.reject {|x| x == server_host} end def remote_server_login diff --git a/config/deploy.rb b/config/deploy.rb index 7d6f88179..b8e123b48 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -105,7 +105,7 @@ end namespace :delayed_job do desc "Start delayed_job process" task :start, :roles => :app do - run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec ruby script/delayed_job start" + run "cd #{current_path}; RAILS_ENV=#{rails_env} bundle exec ruby script/delayed_job --queue=`hostname` start" end desc "Stop delayed_job process" diff --git a/test/factories/upload.rb b/test/factories/upload.rb index df37a781c..83db31400 100644 --- a/test/factories/upload.rb +++ b/test/factories/upload.rb @@ -8,6 +8,7 @@ FactoryGirl.define do tag_string "special" status "pending" server Socket.gethostname + source "xxx" factory(:source_upload) do source "http://www.google.com/intl/en_ALL/images/logo.gif"