diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-07-07 02:46:37 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-07-07 02:46:37 +0200 |
| commit | 7b6af89509e8439fe2474e623ee97e4db67ab011 (patch) | |
| tree | 47aa227de58d566727e8afdc44d7abc0934f22a6 /app/controllers | |
| parent | 527376039c527eb8f559c5e6da76429bc3f3ee4f (diff) | |
Replace awesome_nested_set with a plain parent_id-based NestedTree concern
Root-caused this session: appending a child to any node never widened
that parent's own rgt boundary, on the pinned revision (Gemfile tracked
main directly, chasing a too-conservative gemspec constraint - not, as
first assumed, a deliberate pin to avoid a known bug). Reproduced
cleanly on a single ordinary create with no concurrency and no bulk
operation involved, confirmed via the gem's own SetValidator, then
confirmed as the root cause of nodes_controller_test.rb's 3 long-standing
"pre-existing" failures - not three separate mysteries, one bug.
admin_controller's sitemap needed its own real conversion, not just a
drop-in: awesome_nested_set's lft column implicitly provided correct
depth-first tree order for free, which the old code combined with a
separate class-level each_with_level iterator. Both replaced by one
method, self_and_descendants_ordered_with_level, computing an ordered
[node, level] list in a single query-then-walk pass - checked against
the actual view template first (admin/index.html.erb) rather than
assumed, since it relies on list order alone to render correct visual
nesting.
lft/rgt/depth columns intentionally left in schema, unused - dropping
them is a separate, deliberately deferred migration once this is proven
running for a while, not bundled with the behavior change.
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/admin_controller.rb | 8 |
1 files changed, 3 insertions, 5 deletions
diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index bfc6cd8..3fa0519 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb | |||
| @@ -15,12 +15,10 @@ class AdminController < ApplicationController | |||
| 15 | Time.now, Time.now - 14.days | 15 | Time.now, Time.now - 14.days |
| 16 | ).limit(50).order("updated_at desc") | 16 | ).limit(50).order("updated_at desc") |
| 17 | 17 | ||
| 18 | all_nodes = Node.root.self_and_descendants | 18 | ordered_with_level = Node.root.self_and_descendants_ordered_with_level |
| 19 | @sitemap_depth = {} | 19 | @sitemap_depth = {} |
| 20 | Node.each_with_level(all_nodes) do |node, level| | 20 | ordered_with_level.each { |node, level| @sitemap_depth[node.id] = level } |
| 21 | @sitemap_depth[node.id] = level | 21 | @sitemap = ordered_with_level.map(&:first).reject(&:update?) |
| 22 | end | ||
| 23 | @sitemap = all_nodes.to_a.sort! { |node1,node2| node1.lft <=> node2.lft }.delete_if { |node| node.update? } | ||
| 24 | 22 | ||
| 25 | @mypages = Page.where("user_id = ? or editor_id = ?", @current_user, @current_user) | 23 | @mypages = Page.where("user_id = ? or editor_id = ?", @current_user, @current_user) |
| 26 | 24 | ||
