diff options
| author | erdgeist <erdgeist@erdgeist.org> | 2026-08-07 06:15:14 +0200 |
|---|---|---|
| committer | erdgeist <erdgeist@erdgeist.org> | 2026-08-07 06:15:14 +0200 |
| commit | f4ddfff03ca9f25d50f39a1971877362d85eb9cb (patch) | |
| tree | 31e6774fd4cf2b579a9622277be150417a2fa48e /lib | |
| parent | 02a4ea750428aa1a9c9e7f2680553c0ce4ef1fec (diff) | |
Move the pending address from the node onto the draft
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/tasks/pages.rake | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/tasks/pages.rake b/lib/tasks/pages.rake new file mode 100644 index 00000000..0cfbc5dc --- /dev/null +++ b/lib/tasks/pages.rake | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | namespace :pages do | ||
| 2 | desc "Backfill pages.slug and pages.parent_node_id from each page's " \ | ||
| 3 | "node. Historical accuracy is not attempted. Every revision gets " \ | ||
| 4 | "the node's current address, which is right for head and draft and " \ | ||
| 5 | "harmless for older revisions, and avoids nil checks everywhere. " \ | ||
| 6 | "Dry run unless WRITE=1." | ||
| 7 | task :backfill_address => :environment do | ||
| 8 | write = ENV["WRITE"] == "1" | ||
| 9 | puts "DRY RUN -- nothing written. Re-run with WRITE=1." unless write | ||
| 10 | |||
| 11 | touched = 0 | ||
| 12 | Node.find_each do |node| | ||
| 13 | scope = node.pages.where("slug IS DISTINCT FROM :s OR parent_node_id IS DISTINCT FROM :p", | ||
| 14 | :s => node.slug, :p => node.parent_id) | ||
| 15 | count = scope.count | ||
| 16 | next if count.zero? | ||
| 17 | |||
| 18 | scope.update_all(:slug => node.slug, :parent_node_id => node.parent_id) if write | ||
| 19 | touched += count | ||
| 20 | end | ||
| 21 | |||
| 22 | # Autosaves carry no node_id -- has_many :pages does not cover them. | ||
| 23 | Node.where.not(:autosave_id => nil).includes(:autosave).find_each do |node| | ||
| 24 | a = node.autosave | ||
| 25 | next if a.slug == node.slug && a.parent_node_id == node.parent_id | ||
| 26 | |||
| 27 | a.update_columns(:slug => node.slug, :parent_node_id => node.parent_id) if write | ||
| 28 | touched += 1 | ||
| 29 | end | ||
| 30 | |||
| 31 | puts "#{write ? "updated" : "would update"} #{touched} pages" | ||
| 32 | end | ||
| 33 | end | ||
