fixes to tag alias cache expiration, improved instructions for sign up

This commit is contained in:
albert
2013-03-13 12:15:56 -04:00
parent b40df085d6
commit 656d591806
12 changed files with 47 additions and 33 deletions

View File

@@ -59,7 +59,7 @@ div#c-users {
}
div#a-new {
max-width: 40em;
max-width: 60em;
p {
font-size: 1.2em;

View File

@@ -28,6 +28,8 @@ class TagAliasesController < ApplicationController
def destroy
@tag_alias = TagAlias.find(params[:id])
@tag_alias.update_column(:status, "deleted")
@tag_alias.clear_all_cache
@tag_alias.destroy
respond_with(@tag_alias, :location => tag_aliases_path)
end
@@ -38,10 +40,4 @@ class TagAliasesController < ApplicationController
@tag_alias.delay(:queue => "default").process!
respond_with(@tag_alias, :location => tag_alias_path(@tag_alias))
end
def cache
@tag_alias = TagAlias.find(params[:id])
@tag_alias.clear_cache
render :nothing => true
end
end

View File

@@ -51,7 +51,6 @@ class TagAliasCorrection
def fix!
clear_cache
tag_alias.update_cache
tag_alias.delay(:queue => "default").update_posts
end
end

View File

@@ -1,6 +1,5 @@
class TagAlias < ActiveRecord::Base
after_save :clear_all_cache
after_save :update_cache
after_save :ensure_category_consistency
after_destroy :clear_all_cache
before_validation :initialize_creator, :on => :create
@@ -35,7 +34,25 @@ class TagAlias < ActiveRecord::Base
end
end
module CacheMethods
extend ActiveSupport::Concern
module ClassMethods
def clear_cache_for(name)
Cache.delete("ta:#{Cache.sanitize(name)}")
end
end
def clear_all_cache
Danbooru.config.all_server_hosts.each do |host|
TagAlias.delay(:queue => host).clear_cache_for(antecedent_name)
TagAlias.delay(:queue => host).clear_cache_for(consequent_name)
end
end
end
extend SearchMethods
include CacheMethods
def self.to_aliased(names)
alias_hash = Cache.get_multi(names.flatten, "ta") do |name|
@@ -96,22 +113,6 @@ class TagAlias < ActiveRecord::Base
true
end
def clear_all_cache
Danbooru.config.all_server_hosts.each do |host|
delay(:queue => host).clear_cache
end
end
def clear_cache
Cache.delete("ta:#{Cache.sanitize(antecedent_name)}")
Cache.delete("ta:#{Cache.sanitize(consequent_name)}")
end
def update_cache
Cache.put("ta:#{Cache.sanitize(antecedent_name)}", consequent_name)
Cache.delete("ta:#{Cache.sanitize(consequent_name)}")
end
def update_posts
Post.raw_tag_match(antecedent_name).find_each do |post|
escaped_antecedent_name = Regexp.escape(antecedent_name)

View File

@@ -0,0 +1,9 @@
<div style="width: 60em;">
<h1>Name Change</h1>
<h2>I want to change my name. Why can't I?</h2>
<p>Moderators rely on user names to track identities. For example, if Bob has a history of leaving nasty comments, the mods will know that Bob has a bad reputation. But if Bob decides to change his name to Carl, and Carl starts leaving nasty comments again, the mods won't realize that Bob and Carl are the same person. They might be lenient with Carl instead of banning him.</p>
<p>For this reason user name changes are not supported.</p>
</div>

View File

@@ -4,6 +4,10 @@
<%= simple_form_for @user do |f| %>
<fieldset>
<div class="input">
<label>Name</label>
<p>Name changes are not supported. <%= link_to "Read why", name_change_path %>.</p>
</div>
<%= f.input :email, :required => Danbooru.config.enable_email_verification?, :hint => "Used for messages and for password resets", :as => :email %>
<%= f.input :time_zone, :include_blank => false %>
<%= f.input :receive_email_notifications, :as => :select, :include_blank => false %>

View File

@@ -3,6 +3,10 @@
<h1>Sign Up</h1>
<p>A basic account is <strong>free</strong> and lets you keep favorites, upload artwork, and write comments. If you want <%= link_to "more features", wiki_pages_path(:title => "help:accounts") %> you can upgrade your account later.</p>
<h1 style="margin-bottom: 1em;">This site is open to web crawlers so whatever name you choose will be public!</h1>
<p>This includes favorites, uploads, and comments. Almost everything is public. So don't choose a name you don't want to be associated with.</p>
<div id="p3">
<%= simple_form_for(@user) do |f| %>

View File

@@ -50,7 +50,7 @@
<td>Yes</td>
</tr>
<tr>
<td>See Deleted Posts</td>
<td>See Banned Posts</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
@@ -64,7 +64,7 @@
</tbody>
</table>
</div>
<p>Just provide your email address and details for upgrading your account will be sent to you. If you have any further questions or concerns, feel free to contact me at <%= mail_to Danbooru.config.contact_email, nil, :encode => :javascript %>.</p>
<p>Just provide your email address and details for upgrading your account will be sent to you. <strong>Upgrading from Gold to Platinum will only cost $20.</strong> If you have any further questions or concerns, feel free to contact me at <%= mail_to Danbooru.config.contact_email, nil, :encode => :javascript %>.</p>
<%= form_tag(upgrade_user_path(CurrentUser.user)) do %>
<%= email_field_tag :email, CurrentUser.email %>

View File

@@ -159,7 +159,6 @@ Danbooru::Application.routes.draw do
resources :tag_aliases do
resource :correction, :only => [:new, :create, :show], :controller => "TagAliasCorrections"
member do
delete :cache
post :approve
end
collection do
@@ -304,6 +303,7 @@ Danbooru::Application.routes.draw do
match "/static/mrtg" => "static#mrtg", :as => "mrtg"
match "/static/contact" => "static#contact", :as => "contact"
match "/static/benchmark" => "static#benchmark"
match "/static/name_change" => "static#name_change", :as => "name_change"
root :to => "posts#index"
end

View File

@@ -20,7 +20,7 @@ class AliasAndImplicationImporterTest < ActiveSupport::TestCase
end
should "process it" do
assert_difference("Delayed::Job.count", 3) do
assert_difference("Delayed::Job.count", 4) do
@importer.process!
end
end

View File

@@ -45,6 +45,7 @@ class TagAliasCorrectionTest < ActiveSupport::TestCase
context "that is fixed" do
setup do
@correction.fix!
TagAlias.to_aliased(["aaa"])
end
should "now have the correct cache" do

View File

@@ -32,11 +32,11 @@ class TagAliasTest < ActiveSupport::TestCase
tag1 = FactoryGirl.create(:tag, :name => "aaa")
tag2 = FactoryGirl.create(:tag, :name => "bbb")
ta = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
assert_nil(MEMCACHE.get("ta:aaa"))
ta.update_cache
assert_equal("bbb", MEMCACHE.get("ta:aaa"))
assert_nil(Cache.get("ta:aaa"))
TagAlias.to_aliased(["aaa"])
assert_equal("bbb", Cache.get("ta:aaa"))
ta.destroy
assert_nil(MEMCACHE.get("ta:aaa"))
assert_nil(Cache.get("ta:aaa"))
end
should "update any affected posts when saved" do