diff --git a/Gemfile.lock b/Gemfile.lock index 6858f8b1a..c564232ab 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -46,7 +46,7 @@ GEM activesupport (= 3.1.0.rc1) activesupport (3.1.0.rc1) multi_json (~> 1.0) - arel (2.1.3) + arel (2.1.4) bcrypt-ruby (2.1.4) builder (3.0.0) daemons (1.1.4) @@ -54,9 +54,9 @@ GEM activesupport (~> 3.0) daemons erubis (2.7.0) - factory_girl (1.3.3) + factory_girl (2.0.2) haml (3.1.2) - hike (1.1.0) + hike (1.2.0) i18n (0.6.0) imagesize (0.1.1) mail (2.3.0) @@ -64,10 +64,10 @@ GEM mime-types (~> 1.16) treetop (~> 1.4.8) mechanize (2.0.1) - net-http-digest_auth (~> 1.1, >= 1.1.1) + net-http-digest_auth (>= 1.1.1, ~> 1.1) net-http-persistent (~> 1.8) nokogiri (~> 1.4) - webrobots (~> 0.0, >= 0.0.9) + webrobots (>= 0.0.9, ~> 0.0) memcache-client (1.8.5) mime-types (1.16) mocha (0.9.12) @@ -76,15 +76,15 @@ GEM net-http-persistent (1.8) nokogiri (1.5.0) pg (0.11.0) - polyglot (0.3.1) - rack (1.3.1) + polyglot (0.3.2) + rack (1.3.2) rack-cache (1.0.2) rack (>= 0.4) rack-mount (0.8.1) rack (>= 1.0.0) rack-ssl (1.3.2) rack - rack-test (0.6.0) + rack-test (0.6.1) rack (>= 1.0) rails (3.1.0.rc1) actionmailer (= 3.1.0.rc1) @@ -109,16 +109,17 @@ GEM simplecov (0.4.2) simplecov-html (~> 0.4.4) simplecov-html (0.4.5) - sprockets (2.0.0.beta.10) - hike (~> 1.0) + sprockets (2.0.0.beta.12) + hike (~> 1.2) rack (~> 1.0) - tilt (!= 1.3.0, ~> 1.1) + tilt (~> 1.1, != 1.3.0) super_exception_notifier (3.0.13) actionmailer rake thor (0.14.6) tilt (1.3.2) - treetop (1.4.9) + treetop (1.4.10) + polyglot polyglot (>= 0.3.1) tzinfo (0.3.29) webrobots (0.0.10) diff --git a/app/controllers/tag_aliases_controller.rb b/app/controllers/tag_aliases_controller.rb index 61f4a03d5..7e9f6df95 100644 --- a/app/controllers/tag_aliases_controller.rb +++ b/app/controllers/tag_aliases_controller.rb @@ -15,6 +15,7 @@ class TagAliasesController < ApplicationController def create @tag_alias = TagAlias.create(params[:tag_alias]) + @tag_alias.delay.process! respond_with(@tag_alias, :location => tag_aliases_path(:search => {:id_eq => @tag_alias.id})) end diff --git a/app/controllers/tag_implications_controller.rb b/app/controllers/tag_implications_controller.rb index 91ace2f76..36f829baf 100644 --- a/app/controllers/tag_implications_controller.rb +++ b/app/controllers/tag_implications_controller.rb @@ -15,6 +15,7 @@ class TagImplicationsController < ApplicationController def create @tag_implication = TagImplication.create(params[:tag_implication]) + @tag_implication.delay.process! respond_with(@tag_implication, :location => tag_implications_path(:search => {:id_eq => @tag_implication.id})) end diff --git a/app/models/post.rb b/app/models/post.rb index bac987551..2c9807bcc 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -41,6 +41,7 @@ class Post < ActiveRecord::Base scope :available_for_moderation, lambda {where(["id NOT IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])} scope :hidden_from_moderation, lambda {where(["id IN (SELECT pd.post_id FROM post_disapprovals pd WHERE pd.user_id = ?)", CurrentUser.id])} scope :tag_match, lambda {|query| Post.tag_match_helper(query)} + scope :exact_tag_match, lambda {|query| Post.exact_tag_match_helper(query)} scope :positive, where("score > 1") scope :negative, where("score < -1") search_methods :tag_match @@ -501,6 +502,11 @@ class Post < ActiveRecord::Base relation end + + def exact_tag_match_helper(q) + arel = Post.scoped + add_tag_string_search_relation({:related => [q].flatten, :include => [], :exclude => []}, arel) + end def tag_match_helper(q) unless q.is_a?(Hash) diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index 4eefe90fb..786c87951 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -1,11 +1,7 @@ class TagAlias < ActiveRecord::Base - attr_accessor :creator_ip_addr - after_save :update_posts - after_save :clear_cache - after_save :clear_remote_cache + before_save :clear_all_cache after_save :update_cache - after_destroy :clear_cache - after_destroy :clear_remote_cache + after_destroy :clear_all_cache before_validation :initialize_creator, :on => :create validates_presence_of :creator_id validates_uniqueness_of :antecedent_name @@ -25,8 +21,17 @@ class TagAlias < ActiveRecord::Base alias_hash.values.flatten.uniq end + def process! + update_column(:status, "processing") + update_posts + update_column(:status, "active") + rescue Exception => e + update_column(:status, "error: #{e}") + end + def initialize_creator self.creator_id = CurrentUser.user.id + self.creator_ip_addr = CurrentUser.ip_addr end def antecedent_tag @@ -44,6 +49,11 @@ class TagAlias < ActiveRecord::Base false end end + + def clear_all_cache + clear_cache + clear_remote_cache + end def clear_cache Cache.delete("ta:#{Cache.sanitize(antecedent_name)}") @@ -60,13 +70,15 @@ class TagAlias < ActiveRecord::Base end def update_posts - Post.tag_match(antecedent_name).find_each do |post| + Post.exact_tag_match(antecedent_name).find_each do |post| escaped_antecedent_name = Regexp.escape(antecedent_name) fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_antecedent_name}(?:\Z| )/, " #{consequent_name} ").strip - post.update_attributes( - :tag_string => fixed_tags - ) + CurrentUser.scoped(creator, creator_ip_addr) do + post.update_attributes( + :tag_string => fixed_tags + ) + end end end end diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index 17966d9e8..e0a497f87 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -1,43 +1,19 @@ class TagImplication < ActiveRecord::Base - before_save :clear_cache before_save :update_descendant_names after_save :update_descendant_names_for_parent - after_save :update_cache - after_save :update_posts - after_destroy :clear_cache - after_destroy :clear_remote_cache belongs_to :creator, :class_name => "User" before_validation :initialize_creator, :on => :create validates_presence_of :creator_id validates_uniqueness_of :antecedent_name, :scope => :consequent_name validate :absence_of_circular_relation - - module CacheMethods - def clear_cache - Cache.delete("ti:#{Cache.sanitize(antecedent_name)}") - @descendants = nil - end - - def clear_remote_cache - Danbooru.config.other_server_hosts.each do |server| - Net::HTTP.delete(URI.parse("http://#{server}/tag_implications/#{id}/cache")) - end - end - - def update_cache - descendant_names_array - true - end - end module DescendantMethods extend ActiveSupport::Concern module ClassMethods + # assumes names are normalized def with_descendants(names) - names + Cache.get_multi(names.flatten, "ti") do |name| - ([name] + where(["antecedent_name = ?", name]).all.map {|x| x.descendant_names_array}).flatten - end.values.flatten.uniq + (names + where("antecedent_name in (?)", names).map(&:descendant_names_array)).flatten.uniq end end @@ -55,9 +31,7 @@ class TagImplication < ActiveRecord::Base end def descendant_names_array - Cache.get("ti:#{Cache.sanitize(antecedent_name)}") do - descendant_names.split(/ /) - end + descendant_names.split(/ /) end def update_descendant_names @@ -93,12 +67,20 @@ class TagImplication < ActiveRecord::Base end end - include CacheMethods include DescendantMethods include ParentMethods def initialize_creator self.creator_id = CurrentUser.user.id + self.creator_ip_addr = CurrentUser.ip_addr + end + + def process! + update_column(:status, "processing") + update_posts + update_column(:status, "active") + rescue Exception => e + update_column(:status, "error: #{e}") end def absence_of_circular_relation @@ -110,12 +92,14 @@ class TagImplication < ActiveRecord::Base end def update_posts - Post.tag_match(antecedent_name).find_each do |post| + Post.exact_tag_match(antecedent_name).find_each do |post| escaped_antecedent_name = Regexp.escape(antecedent_name) fixed_tags = post.tag_string.sub(/(?:\A| )#{escaped_antecedent_name}(?:\Z| )/, " #{antecedent_name} #{descendant_names} ").strip - post.update_attributes( - :tag_string => fixed_tags - ) + CurrentUser.scoped(creator, creator_ip_addr) do + post.update_attributes( + :tag_string => fixed_tags + ) + end end end diff --git a/app/views/static/jquery_test.html.erb b/app/views/static/jquery_test.html.erb deleted file mode 100644 index 261abb8cc..000000000 --- a/app/views/static/jquery_test.html.erb +++ /dev/null @@ -1,40 +0,0 @@ -
By accessing the "<%= Danbooru.config.app_name %>" website ("Site") you agree to the following terms of service. If you do not agree to these terms, then please do not access the Site.
You cannot upload a post or comment during the first week of signing up.
After the initial period, you can post up to one comment an hour and a variable number of posts based on how many of your previous uploads were approved or deleted.
In addition, you may not use the Site to upload any of the following:
If you believe a post infringes upon your copyright, please send an email to the <%= mail_to Danbooru.config.contact_email, "webmaster", :encode => "hex" %> with the following pieces of information:
The Site will not disclose the IP address, email address, password, or DMails of any user except to the staff.
The Site is allowed to make public everything else, including but not limited to: uploaded posts, favorited posts, comments, forum posts, wiki edits, and note edits.
By clicking on the "I Agree" link, you have read all the terms and have agreed to them.
<%= link_to("I Agree", params[:url] || "/", :onclick => "Cookie.put('tos', '1')") %> | <%= link_to("Cancel", "/") %>