diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-10 21:57:58 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-10 21:57:58 +0200 |
| commit | 7d6a665b896252537b8b8df2f15e204d04417231 (patch) | |
| tree | 37b8d5434426646a019c6d5c8c12f7bb8a4de647 | |
| parent | 48eed5f35ea798c91f1e0a77c13e751145acfc48 (diff) | |
Fix current_user/uniq inconsistencies in admin#index, remove dead query
@mynodes used the bare @current_user ivar instead of the current_user
method (works today only because login_required already forces that
memoization; every other query and controller in this app uses the
method), and .uniq, which is plain Enumerable#uniq here, not
Relation#distinct -- it materializes every joined row into an Array
before deduplicating, rather than deduplicating in SQL.
@mypages had the same ivar pattern, no .order/.limit unlike every
sibling query in this action, and -- confirmed via a full grep -- is
referenced nowhere else in the codebase. Removed rather than bounded;
nothing was ever rendering it.
| -rw-r--r-- | app/controllers/admin_controller.rb | 8 | ||||
| -rw-r--r-- | test/controllers/admin_controller_test.rb | 20 |
2 files changed, 23 insertions, 5 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 6ab2135..435df57 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb | |||
| @@ -20,12 +20,10 @@ class AdminController < ApplicationController | |||
| 20 | ordered_with_level.each { |node, level| @sitemap_depth[node.id] = level } | 20 | ordered_with_level.each { |node, level| @sitemap_depth[node.id] = level } |
| 21 | @sitemap = ordered_with_level.map(&:first).reject(&:update?) | 21 | @sitemap = ordered_with_level.map(&:first).reject(&:update?) |
| 22 | 22 | ||
| 23 | @mypages = Page.where("user_id = ? or editor_id = ?", @current_user, @current_user) | ||
| 24 | |||
| 25 | @mynodes = Node.joins(:pages) | 23 | @mynodes = Node.joins(:pages) |
| 26 | .where("pages.user_id = ? or pages.editor_id = ?", @current_user, @current_user) | 24 | .where("pages.user_id = ? or pages.editor_id = ?", current_user, current_user) |
| 27 | .order("updated_at desc") | 25 | .order("updated_at desc") |
| 28 | .uniq.first(50) | 26 | .distinct.first(50) |
| 29 | end | 27 | end |
| 30 | 28 | ||
| 31 | def conventions | 29 | def conventions |
diff --git a/test/controllers/admin_controller_test.rb b/test/controllers/admin_controller_test.rb index d6005ba..13cc1bb 100644 --- a/test/controllers/admin_controller_test.rb +++ b/test/controllers/admin_controller_test.rb | |||
| @@ -14,4 +14,24 @@ class AdminControllerTest < ActionController::TestCase | |||
| 14 | get :index | 14 | get :index |
| 15 | assert_includes assigns(:drafts), node | 15 | assert_includes assigns(:drafts), node |
| 16 | end | 16 | end |
| 17 | |||
| 18 | test "my work list shows each matching node only once, even with several revisions by the same user" do | ||
| 19 | login_as :quentin | ||
| 20 | user = User.find_by_login("quentin") | ||
| 21 | node = Node.root.children.create!(:slug => "dedup_test") | ||
| 22 | node.lock_for_editing!(user) | ||
| 23 | node.autosave!({:title => "v1"}, user) | ||
| 24 | node.save_draft!(user) | ||
| 25 | node.publish_draft! | ||
| 26 | node.lock_for_editing!(user) | ||
| 27 | node.autosave!({:title => "v2"}, user) | ||
| 28 | node.save_draft!(user) | ||
| 29 | node.publish_draft! | ||
| 30 | # three pages now exist on this node, all touched by quentin -- | ||
| 31 | # without DISTINCT, the join would return this node three times | ||
| 32 | |||
| 33 | get :index | ||
| 34 | matches = assigns(:mynodes).select { |n| n.id == node.id } | ||
| 35 | assert_equal 1, matches.length | ||
| 36 | end | ||
| 17 | end | 37 | end |
