Merge branch 'subscription-queries'
This commit is contained in:
@@ -12,4 +12,8 @@ div#c-tag-subscriptions {
|
||||
font-size: $h3_size;
|
||||
}
|
||||
}
|
||||
|
||||
.hint {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ class TagSubscription < ActiveRecord::Base
|
||||
before_save :limit_tag_count
|
||||
attr_accessible :name, :tag_query, :post_ids, :is_public, :is_visible_on_profile
|
||||
validates_presence_of :name, :tag_query, :creator_id
|
||||
validates_format_of :tag_query, :with => /\A(?:\S*\s*){1,20}\Z/, :message => "can have up to 20 tags"
|
||||
validates_format_of :tag_query, :with => /\A(?:[^\r\n]*(?:\r?\n)*){1,20}\Z/, :message => "can have up to 20 queries"
|
||||
validate :creator_can_create_subscriptions, :on => :create
|
||||
|
||||
def normalize_name
|
||||
@@ -17,6 +17,10 @@ class TagSubscription < ActiveRecord::Base
|
||||
name.tr("_", " ")
|
||||
end
|
||||
|
||||
def pretty_tag_query
|
||||
tag_query_array.join(", ")
|
||||
end
|
||||
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.id
|
||||
end
|
||||
@@ -35,7 +39,7 @@ class TagSubscription < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def tag_query_array
|
||||
Tag.scan_query(tag_query)
|
||||
tag_query.scan(/[^\r\n]+/)
|
||||
end
|
||||
|
||||
def limit_tag_count
|
||||
@@ -44,8 +48,8 @@ class TagSubscription < ActiveRecord::Base
|
||||
|
||||
def process
|
||||
divisor = [tag_query_array.size / 2, 1].max
|
||||
post_ids = tag_query_array.inject([]) do |all, tag|
|
||||
all += Post.tag_match(tag).limit(Danbooru.config.tag_subscription_post_limit / divisor).select("posts.id").order("posts.id DESC").map(&:id)
|
||||
post_ids = tag_query_array.inject([]) do |all, query|
|
||||
all += Post.tag_match(query).limit(Danbooru.config.tag_subscription_post_limit / divisor).select("posts.id").order("posts.id DESC").map(&:id)
|
||||
end
|
||||
self.post_ids = post_ids.sort.reverse.slice(0, Danbooru.config.tag_subscription_post_limit).join(",")
|
||||
end
|
||||
@@ -103,7 +107,7 @@ class TagSubscription < ActiveRecord::Base
|
||||
relation = relation.where(["name ILIKE ? ESCAPE E'\\\\'", sub_group.to_escaped_for_sql_like])
|
||||
end
|
||||
|
||||
relation.map {|x| x.tag_query.split(/ /)}.flatten
|
||||
relation.map {|x| x.tag_query.split(/\r?\n/)}.flatten
|
||||
else
|
||||
[]
|
||||
end
|
||||
@@ -134,8 +138,8 @@ class TagSubscription < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.process_all
|
||||
CurrentUser.scoped(User.admins.first, "127.0.0.1") do
|
||||
find_each do |tag_subscription|
|
||||
find_each do |tag_subscription|
|
||||
CurrentUser.scoped(tag_subscription.creator, "127.0.0.1") do
|
||||
if $job_task_daemon_active != false && tag_subscription.creator.is_gold? && tag_subscription.is_active?
|
||||
begin
|
||||
tag_subscription.process
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<%= simple_form_for(@tag_subscription) do |f| %>
|
||||
<%= f.input :name %>
|
||||
<%= f.input :tag_query %>
|
||||
<%= f.input :tag_query, :hint => "Put separate tag combinations on separate lines." %>
|
||||
<div class="input">
|
||||
<label for="tag_subscription_is_public">
|
||||
<%= check_box "tag_subscription", "is_public" %>
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<% @tag_subscriptions.each do |tag_subscription| %>
|
||||
<tr>
|
||||
<td><%= tag_subscription.pretty_name %></td>
|
||||
<td><%= tag_subscription.tag_query %></td>
|
||||
<td><%= tag_subscription.pretty_tag_query %></td>
|
||||
<td><%= tag_subscription.post_id_array.size %></td>
|
||||
<td>
|
||||
<%= link_to "edit", edit_tag_subscription_path(tag_subscription) %>
|
||||
@@ -26,7 +26,7 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<p class="info">You can create up to <%= Danbooru.config.max_tag_subscriptions %> subscriptions with up to 20 tags each.</p>
|
||||
<p class="info">You can create up to <%= Danbooru.config.max_tag_subscriptions %> subscriptions with up to 20 queries each.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
class ChangeTagSubscriptionTagQueryDelimiter < ActiveRecord::Migration
|
||||
def change
|
||||
execute "set statement_timeout = 0"
|
||||
TagSubscription.find_each do |tag_subscription|
|
||||
tag_subscription.update_column(:tag_query, tag_subscription.tag_query.scan(/\S+/).join("\n"))
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user