add postarchive model, fixes #2831: Replace Subscriptions Link With Search:All Link

This commit is contained in:
Albert Yi
2017-01-11 11:32:29 -08:00
parent f1ffd6d9c9
commit 0ab45ebc42
8 changed files with 63 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ module Moderator
module Post
class ApprovalsController < ApplicationController
before_filter :approver_only
skip_before_filter :api_check
def create
cookies.permanent[:moderated] = Time.now.to_i

View File

@@ -2,6 +2,7 @@ module Moderator
module Post
class DisapprovalsController < ApplicationController
before_filter :approver_only
skip_before_filter :api_check
def create
cookies.permanent[:moderated] = Time.now.to_i

View File

@@ -4,6 +4,7 @@ module Moderator
before_filter :approver_only, :only => [:delete, :undelete, :move_favorites, :ban, :unban, :confirm_delete, :confirm_move_favorites, :confirm_ban]
before_filter :admin_only, :only => [:expunge]
rescue_from ::PostFlag::Error, ::Post::ApprovalError, :with => :rescue_exception
skip_before_filter :api_check
def confirm_delete
@post = ::Post.find(params[:id])

View File

@@ -5,6 +5,7 @@ module Moderator
respond_to :html, :json
before_filter :approver_only
skip_before_filter :api_check
def show
cookies.permanent[:moderated] = Time.now.to_i

View File

@@ -173,6 +173,10 @@ module PostSets
tag_subscription.present?
end
def is_saved_search?
tag_string =~ /search:/
end
def tag_subscription
@tag_subscription ||= tag_array.select {|x| x =~ /^sub:/}.map {|x| x.sub(/^sub:/, "")}.first
end

View File

@@ -0,0 +1,49 @@
class PostArchive < ActiveRecord::Base
def self.enabled?
Danbooru.config.aws_sqs_archives_url.present?
end
establish_connection "archive_#{Rails.env}".to_sym if enabled?
self.table_name = "post_versions"
def self.calculate_version(post_id, updated_at)
1 + PostVersion.where("post_id = ? and updated_at <= ?", post_id, updated_at).count
end
def self.export(version_id = 0)
PostVersion.where("id > version_id").find_each do |version|
previous = version.previous
tags = version.tags.scan(/\S+/)
if previous
added_tags = tags - previous.tags
removed_tags = previous.tags - tags
else
added_tags = tags
removed_tags = []
end
rating_changed = previous.nil? || version.rating != previous.try(:rating)
parent_changed = previous.nil? || version.parent_id != previous.try(:parent_id)
source_changed = previous.nil? || version.source != previous.try(:source)
create(
post_id: version.post_id,
tags: version.tags,
added_tags: added_tags,
removed_tags: removed_tags,
updater_id: version.updater_id],
updater_ip_addr: version.updater_ip_addr.to_s,
created_at: version.created_at,
updated_at: version.updated_at,
version: calculate_version(version.post_id, version.updated_at),
rating: version.rating,
rating_changed: rating_changed,
parent_id: version.parent_id,
parent_changed: parent_changed,
source: version.source,
source_changed: source_changed
)
puts "inserted #{version.id}"
end
end
end

View File

@@ -11,7 +11,7 @@
<li><%= link_to "Favorites", favorites_path %></li>
<li><%= link_to "Favorite groups", favorite_groups_path %></li>
<% if CurrentUser.has_saved_searches? %>
<li><%= link_to "Saved searches", saved_searches_path %></li>
<li><%= link_to "Saved searches", posts_path(:tags => "search:all") %></li>
<% end %>
<li><%= link_to "Subscriptions", posts_path(:tags => "sub:#{CurrentUser.name}") %></li>
<% end %>

View File

@@ -4,7 +4,11 @@
<li><%= link_to "Deleted posts", posts_path(:tags => "#{params[:tags]} status:deleted"), :rel => "nofollow" %></li>
<% if @post_set.is_tag_subscription? %>
<li><%= link_to "Edit subscriptions", tag_subscriptions_path %></li>
<li><%= link_to "Manage subscriptions", tag_subscriptions_path %></li>
<% end %>
<% if @post_set.is_saved_search? %>
<li><%= link_to "Manage saved searches", saved_searches_path %></li>
<% end %>
<li><%= link_to "Random post", random_posts_path(:tags => params[:tags]), :id => "random-post", :rel => "nofollow" %></li>