tweaks to similar posts

This commit is contained in:
Albert Yi
2018-07-20 15:05:51 -07:00
parent 6fb20fca89
commit df6e86551a
5 changed files with 32 additions and 7 deletions

View File

@@ -438,6 +438,7 @@
$("#comments").show(); $("#comments").show();
$("#edit").hide(); $("#edit").hide();
$("#share").hide(); $("#share").hide();
$("#similar").hide();
} else if (e.target.hash === "#edit") { } else if (e.target.hash === "#edit") {
$("#edit").show(); $("#edit").show();
$("#comments").hide(); $("#comments").hide();
@@ -445,11 +446,18 @@
$("#post_tag_string").focus().selectEnd().height($("#post_tag_string")[0].scrollHeight); $("#post_tag_string").focus().selectEnd().height($("#post_tag_string")[0].scrollHeight);
$("#related-tags-button").trigger("click"); $("#related-tags-button").trigger("click");
$("#find-artist-button").trigger("click"); $("#find-artist-button").trigger("click");
$("#similar").hide();
} else if (e.target.hash === "#similar") {
$("#comments").hide();
$("#edit").hide();
$("#share").hide();
$("#similar").show();
} else { } else {
$("#edit").hide(); $("#edit").hide();
$("#comments").hide(); $("#comments").hide();
$("#share").show(); $("#share").show();
addthis.init(); addthis.init();
$("#similar").hide();
} }
$("#post-sections li").removeClass("active"); $("#post-sections li").removeClass("active");
@@ -460,6 +468,9 @@
$("#post-sections li:first-child").addClass("active"); $("#post-sections li:first-child").addClass("active");
$("#notes").hide(); $("#notes").hide();
$("#edit").hide(); $("#edit").hide();
if ($("#similar").length) {
$("#comments").hide();
}
} }
Danbooru.Post.resize_ugoira_controls = function() { Danbooru.Post.resize_ugoira_controls = function() {

View File

@@ -176,7 +176,7 @@ class ApplicationController < ActionController::Base
def reset_current_user def reset_current_user
CurrentUser.user = nil CurrentUser.user = nil
CurrentUser.ip_addr = nil CurrentUser.ip_addr = nil
CurrentUser.root_url = root_url.sub(/\/$/, "") CurrentUser.root_url = root_url
end end
def set_started_at_session def set_started_at_session

View File

@@ -8,7 +8,7 @@ module PostSets
def posts def posts
@posts ||= begin @posts ||= begin
response = RecommenderService.similar(@post) response = RecommenderService.similar(@post)
post_ids = response.reject {|x| x[0] == @post.id}.slice(0, 5).map {|x| x[0]} post_ids = response.reject {|x| x[0] == @post.id}.slice(0, 6).map {|x| x[0]}
::Post.find(post_ids) ::Post.find(post_ids)
end end
end end

View File

@@ -6,10 +6,16 @@ module RecommenderService
end end
def available?(post) def available?(post)
return true if Rails.env.development?
enabled? && CurrentUser.id == 1 && post.created_at > 6.months.ago && post.score >= 10 enabled? && CurrentUser.id == 1 && post.created_at > 6.months.ago && post.score >= 10
end end
def similar(post) def similar(post)
if Danbooru.config.recommender_server == "development"
return Post.order("random()").limit(6).map {|x| [x.id, "1.000"]}
end
Cache.get("rss:#{post.id}", 1.day) do Cache.get("rss:#{post.id}", 1.day) do
resp = HTTParty.get( resp = HTTParty.get(
"#{Danbooru.config.recommender_server}/similar/#{post.id}", "#{Danbooru.config.recommender_server}/similar/#{post.id}",

View File

@@ -82,22 +82,30 @@
</div> </div>
<% end %> <% end %>
<% if RecommenderService.available?(@post) %>
<%= render "posts/partials/index/similar", post: @post %>
<% end %>
<% if @post.presenter.has_nav_links?(self) %> <% if @post.presenter.has_nav_links?(self) %>
<%= render "posts/partials/show/nav_links", :post => @post, :position => "bottom" %> <%= render "posts/partials/show/nav_links", :post => @post, :position => "bottom" %>
<% end %> <% end %>
<menu id="post-sections"> <menu id="post-sections">
<% if RecommenderService.available?(@post) %>
<li><a href="#similar">Similar</a></li>
<% end %>
<li><a href="#comments">Comments</a></li> <li><a href="#comments">Comments</a></li>
<% if CurrentUser.is_member? && @post.visible? %> <% if CurrentUser.is_member? && @post.visible? %>
<li><a href="#edit" id="post-edit-link">Edit</a></li> <li><a href="#edit" id="post-edit-link">Edit</a></li>
<% end %> <% end %>
<li><a href="#share">Share</a></li> <li><a href="#share">Share</a></li>
</menu> </menu>
<% if RecommenderService.available?(@post) %>
<section id="similar">
<%= render "posts/partials/index/similar", post: @post %>
</section>
<% end %>
<section id="comments"> <section id="comments">
<% if !CurrentUser.user.is_builder? %> <% if !CurrentUser.user.is_builder? %>
<h2>Before commenting, read the <%= link_to "how to comment guide", wiki_pages_path(:search => {:title => "howto:comment"}) %>.</h2> <h2>Before commenting, read the <%= link_to "how to comment guide", wiki_pages_path(:search => {:title => "howto:comment"}) %>.</h2>