blob: 40de80486201824951889fef76b9cb2ece2e8402 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# frozen_string_literal: true
namespace :booru do
task recount_votes: :environment do
puts 'Recounting votes for all posts (be patient!)'
i = 0
Post.includes(:votes).find_each do |p|
p.recount_votes!
i += 1
if (i % 10000) == 0
puts "Done #{i} posts..."
end
end
end
namespace :reindex do
desc 'Rebuild all indices'
task all: :environment do
puts 'Rebuild Reports...'
Report.__elasticsearch__.import(force: true)
puts 'Rebuild Galleries...'
Gallery.__elasticsearch__.import(force: true)
puts 'Rebuild Forum Posts...'
ForumPost.__elasticsearch__.import(force: true)
puts 'Rebuild Filters...'
Filter.__elasticsearch__.import(force: true)
puts 'Rebuild Comments...'
Comment.__elasticsearch__.import(force: true)
puts 'Rebuild Posts (this can take hours)...'
Post.__elasticsearch__.import(force: true)
end
desc 'Rebuild Post indices'
task posts: :environment do
puts 'Rebuild Posts (this can take hours)...'
Post.__elasticsearch__.import(force: true)
end
end
namespace :forums do
desc 'Build topic positions'
task build_topic_positions: :environment do
count = Topic.count
c = 0
Topic.each do |topic|
puts "Building topic positions for topic '#{topic.title}' (#{c} of #{count})"
i = 0
c += 1
topic.posts.order(created_at: :asc).select([:id, :topic_position]).each do |post|
puts "Setting #{post.id} to #{i}"
post.set(topic_position: i)
i += 1
end
end
end
desc 'Build topic post counts'
task build_topic_post_counts: :environment do
Topic.each do |topic|
topic.set(post_count: topic.posts.where(hidden_from_users: false).count)
end
Forum.each do |forum|
forum.set(post_count: forum.topics.where(hidden_from_users: false).sum(:post_count))
forum.set(topic_count: forum.topics.where(hidden_from_users: false).size)
end
end
end
end
|