implement post version search report in danbooru (probably broken)

This commit is contained in:
r888888888
2016-09-06 18:02:58 -07:00
parent 1488f82b32
commit 310538dd71
6 changed files with 53 additions and 49 deletions

View File

@@ -28,13 +28,6 @@ class ReportsController < ApplicationController
end
def post_versions_create
if params[:type] == "added"
@report = Reports::PostVersionsAdded.new(params[:tag], params[:email])
else
@report = Reports::PostVersionsRemoved.new(params[:tag], params[:email])
end
@report.process!
flash[:notice] = "Report is being generated and will be emailed to you shortly"
redirect_to reports_post_versions_path
@report = Reports::PostVersions.new(params[:tag], params[:type])
end
end

View File

@@ -0,0 +1,37 @@
module Reports
class PostVersions
attr_reader :tag, :query
def initialize(tag, query_type)
@tag = tag
if query_type == "added"
@query = BigQuery::PostVersion.new.find_added(tag)
else
@query = BigQuery::PostVersion.new.find_removed(tag)
end
end
def mock_version(raw)
PostVersion.new.tap do |x|
x.id = row["f"][0]["v"]
x.post_id = row["f"][1]["v"]
x.updated_at = Time.at(row["f"][2]["v"].to_f)
x.updater_id = row["f"][3]["v"]
x.updater_ip_addr = row["f"][4]["v"]
x.tags = row["f"][5]["v"]
# x.added_tags = row["f"][6]["v"]
# x.removed_tags = row["f"][7]["v"]
x.parent_id = row["f"][8]["v"]
x.rating = row["f"][9]["v"]
x.source = row["f"][10]["v"]
end
end
def post_versions
if query["rows"].present?
query["rows"].map {|x| mock_version(x)}
end
end
end
end

View File

@@ -1,17 +0,0 @@
module Reports
class PostVersionsAdded
attr_reader :tag, :email
def initialize(tag, email)
@tag = tag
@email = email
end
def process!
if tag
json = {"type" => "post_versions_added", "tag" => tag, "email" => email}.to_json
SqsService.new(Danbooru.config.aws_sqs_post_versions_url).send_message(json)
end
end
end
end

View File

@@ -1,17 +0,0 @@
module Reports
class PostVersionsRemoved
attr_reader :tag, :email
def initialize(tag, email)
@tag = tag
@email = email
end
def process!
if tag
json = {"type" => "post_versions_removed", "tag" => tag, "email" => email}.to_json
SqsService.new(Danbooru.config.aws_sqs_post_versions_url).send_message(json)
end
end
end
end

View File

@@ -2,7 +2,7 @@
<div id="a-post-versions">
<h1>Post Changes Report</h1>
<p>You can search all post changes to find when and where a tag was added or removed. Because these queries can take a long time to generate the results will be emailed to you. Only the 1,000 most recent changes will be returned.</p>
<p>You can search all post changes to find when and where a tag was added or removed. Only the 1,000 most recent changes will be returned.</p>
<%= form_tag(reports_post_versions_create_path, :method => :post, :class => "simple_form") do %>
<div class="input">
@@ -10,12 +10,6 @@
<%= text_field_tag "tag" %>
<%= select_tag "type", options_for_select(%w(added removed)) %>
</div>
<div class="input">
<label for="Email">Email</label>
<%= text_field_tag "email", CurrentUser.user.email %>
</div>
<%= submit_tag "Submit", :data => { :disable_with => "Submitting..." } %>
<% end %>

View File

@@ -0,0 +1,14 @@
<div id="c-reports">
<div id="a-post-versions">
<h1>Post Changes Report</h1>
<p>Only the 1,000 most recent changes are displayed.</p>
<%= render "post_versions/listing", :post_versions => @report.post_versions %>
</div>
</div>
<% content_for(:page_title) do %>
Post Changes Report - <%= Danbooru.config.app_name %>
<% end %>