From e6d1842545326b75df4d2b8b12c45b769ca13fca Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 23 Apr 2017 14:26:23 -0500 Subject: [PATCH 1/3] /notes: default to listing notes, not posts. Remove group_by=post. The posts listing is replaced by a link to order:note. --- app/controllers/notes_controller.rb | 30 ++++--------------- app/logical/post_sets/note.rb | 17 ----------- app/views/layouts/_main_links.html.erb | 2 +- app/views/notes/_secondary_links.html.erb | 3 +- ...{index_by_note.html.erb => index.html.erb} | 0 app/views/notes/index_by_post.html.erb | 17 ----------- 6 files changed, 8 insertions(+), 61 deletions(-) delete mode 100644 app/logical/post_sets/note.rb rename app/views/notes/{index_by_note.html.erb => index.html.erb} (100%) delete mode 100644 app/views/notes/index_by_post.html.erb diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 6cb207108..1bbba3129 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -6,10 +6,11 @@ class NotesController < ApplicationController end def index - if params[:group_by] == "note" - index_by_note - else - index_by_post + @notes = Note.search(params[:search]).order("id desc").paginate(params[:page], :limit => params[:limit], :search_count => params[:search]) + respond_with(@notes) do |format| + format.xml do + render :xml => @notes.to_xml(:root => "notes") + end end end @@ -66,25 +67,4 @@ private def create_params params.require(:note).permit(:x, :y, :width, :height, :body, :post_id, :html_id) end - - def index_by_post - @post_set = PostSets::Note.new(params) - @posts = @post_set.posts - respond_with(@posts) do |format| - format.html {render :action => "index_by_post"} - format.xml do - render :xml => @posts.to_xml(:root => "posts") - end - end - end - - def index_by_note - @notes = Note.search(params[:search]).order("id desc").paginate(params[:page], :limit => params[:limit], :search_count => params[:search]) - respond_with(@notes) do |format| - format.html {render :action => "index_by_note"} - format.xml do - render :xml => @notes.to_xml(:root => "notes") - end - end - end end diff --git a/app/logical/post_sets/note.rb b/app/logical/post_sets/note.rb deleted file mode 100644 index 99a0e9087..000000000 --- a/app/logical/post_sets/note.rb +++ /dev/null @@ -1,17 +0,0 @@ -module PostSets - class Note < PostSets::Post - attr_reader :params - - def initialize(params) - # don't call super because we don't want to repeat these queries - @params = params - @tag_array = Tag.scan_query(params[:tags]) - @page = params[:page] || 1 - @posts = ::Post.tag_match(tag_string).has_notes.paginate(page, :limit => limit).reorder("last_noted_at desc") - end - - def limit - [(params[:limit] || CurrentUser.user.per_page).to_i, 1_000].min - end - end -end diff --git a/app/views/layouts/_main_links.html.erb b/app/views/layouts/_main_links.html.erb index bd2a7a4fe..b5606d77d 100644 --- a/app/views/layouts/_main_links.html.erb +++ b/app/views/layouts/_main_links.html.erb @@ -6,7 +6,7 @@ <% end %> <%= nav_link_to("Posts", posts_path) %> <%= nav_link_to("Comments", comments_path(:group_by => "post")) %> - <%= nav_link_to("Notes", notes_path(:group_by => "post")) %> + <%= nav_link_to("Notes", notes_path) %> <%= nav_link_to("Artists", artists_path) %> <%= nav_link_to("Tags", tags_path) %> <% if CurrentUser.is_builder? %> diff --git a/app/views/notes/_secondary_links.html.erb b/app/views/notes/_secondary_links.html.erb index 0e607b6c0..27ea91845 100644 --- a/app/views/notes/_secondary_links.html.erb +++ b/app/views/notes/_secondary_links.html.erb @@ -1,7 +1,8 @@ <% content_for(:secondary_links) do %>
  • <%= render "notes/quick_search" %>
  • -
  • <%= link_to "Listing", notes_path(:group_by => "post") %>
  • +
  • <%= link_to "Listing", notes_path %>
  • +
  • <%= link_to "Posts", posts_path(:tags => "order:note") %>
  • <%= link_to "Search", search_notes_path %>
  • <%= link_to "History", note_versions_path %>
  • <%= link_to "Requests", posts_path(:tags => "translation_request") %>
  • diff --git a/app/views/notes/index_by_note.html.erb b/app/views/notes/index.html.erb similarity index 100% rename from app/views/notes/index_by_note.html.erb rename to app/views/notes/index.html.erb diff --git a/app/views/notes/index_by_post.html.erb b/app/views/notes/index_by_post.html.erb deleted file mode 100644 index e455c8dc4..000000000 --- a/app/views/notes/index_by_post.html.erb +++ /dev/null @@ -1,17 +0,0 @@ -
    -
    -

    Notes

    - - <%= render "posts/partials/common/inline_blacklist" %> - - <%= @post_set.presenter.post_previews_html(self) %> - - <%= numbered_paginator(@posts, false) %> -
    -
    - -<%= render "secondary_links" %> - -<% content_for(:page_title) do %> - Notes - <%= Danbooru.config.app_name %> -<% end %> From 989917cb07127d77481b39104181c765f08c9a2f Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 23 Apr 2017 14:33:52 -0500 Subject: [PATCH 2/3] /notes, /note_versions: use numbered paginator. --- app/views/note_versions/index.html.erb | 2 +- app/views/notes/index.html.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/note_versions/index.html.erb b/app/views/note_versions/index.html.erb index 89814a828..7423a0927 100644 --- a/app/views/note_versions/index.html.erb +++ b/app/views/note_versions/index.html.erb @@ -53,7 +53,7 @@ - <%= sequential_paginator(@note_versions) %> + <%= numbered_paginator(@note_versions) %> <%= render "notes/secondary_links" %> diff --git a/app/views/notes/index.html.erb b/app/views/notes/index.html.erb index e21e17978..c588ca160 100644 --- a/app/views/notes/index.html.erb +++ b/app/views/notes/index.html.erb @@ -28,7 +28,7 @@ - <%= sequential_paginator(@notes) %> + <%= numbered_paginator(@notes) %> From 808fe0411a7c4deb51b9b37257b01e12169e3f2e Mon Sep 17 00:00:00 2001 From: evazion Date: Sun, 23 Apr 2017 14:54:33 -0500 Subject: [PATCH 3/3] /notes, /note_versions: fix N+1 queries on note creators, updaters. --- app/controllers/note_versions_controller.rb | 1 + app/controllers/notes_controller.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/app/controllers/note_versions_controller.rb b/app/controllers/note_versions_controller.rb index 53fde4995..bcf9380c7 100644 --- a/app/controllers/note_versions_controller.rb +++ b/app/controllers/note_versions_controller.rb @@ -4,6 +4,7 @@ class NoteVersionsController < ApplicationController def index @note_versions = NoteVersion.search(params[:search]).order("note_versions.id desc").paginate(params[:page], :limit => params[:limit]) respond_with(@note_versions) do |format| + format.html { @note_versions = @note_versions.includes(:updater) } format.xml do render :xml => @note_versions.to_xml(:root => "note-versions") end diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 1bbba3129..bed70f667 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -8,6 +8,7 @@ class NotesController < ApplicationController def index @notes = Note.search(params[:search]).order("id desc").paginate(params[:page], :limit => params[:limit], :search_count => params[:search]) respond_with(@notes) do |format| + format.html { @notes = @notes.includes(:creator) } format.xml do render :xml => @notes.to_xml(:root => "notes") end