-
Notifications
You must be signed in to change notification settings - Fork 510
/
search.rake
109 lines (94 loc) · 3.81 KB
/
search.rake
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# frozen_string_literal: true
namespace :search do
BATCH_SIZE = 1000
desc "Update all index mappings"
task(update_all_mappings: :environment) do
# If multiple indexers share an index and a mapping, we only need to call
# create_mapping on one of them.
Indexer.all.group_by(&:index_name).values.map(&:first).map(&:create_mapping)
end
desc "Recreate tag index"
task(index_tags: :environment) do
if Rails.env.production? || Rails.env.test?
puts 'Running this task will temporarily empty some wrangling bins and affect tag search.
Have you warned the wrangling team this task is being run?
Enter YES to continue:'
confirmation = $stdin.gets.chomp.strip.upcase
unless confirmation == "YES"
puts "Task aborted."
exit
end
end
TagIndexer.index_all
end
desc "Recreate pseud index"
task(index_pseuds: :environment) do
PseudIndexer.index_all
end
desc "Recreate work index"
task(index_works: :environment) do
WorkIndexer.index_all
WorkCreatorIndexer.index_from_db
end
desc "Recreate bookmark index"
task(index_bookmarks: :environment) do
BookmarkIndexer.index_all
end
desc "Reindex all works without recreating the index"
task(reindex_works: :environment) do
WorkIndexer.index_from_db
WorkCreatorIndexer.index_from_db
end
desc "Reindex all bookmarkables without recreating the index"
task(reindex_bookmarkables: :environment) do
BookmarkedExternalWorkIndexer.index_from_db
BookmarkedSeriesIndexer.index_from_db
BookmarkedWorkIndexer.index_from_db
end
desc "Reindex all recently-modified items"
task timed_all: %i[timed_works timed_tags timed_pseud timed_bookmarks] do
end
desc "Reindex recent bookmarks"
task timed_bookmarks: :environment do
time = ENV["TIME_PERIOD"] || "NOW() - INTERVAL 1 DAY"
ExternalWork.where("external_works.updated_at > #{time}").select(:id).find_in_batches(batch_size: BATCH_SIZE) do |group|
AsyncIndexer.new(BookmarkedExternalWorkIndexer, :world).enqueue_ids(group.map(&:id))
end
Series.where("series.updated_at > #{time}").select(:id).find_in_batches(batch_size: BATCH_SIZE) do |group|
AsyncIndexer.new(BookmarkedSeriesIndexer, :world).enqueue_ids(group.map(&:id))
end
Work.where("works.revised_at > #{time}").select(:id).find_in_batches(batch_size: BATCH_SIZE) do |group|
AsyncIndexer.new(BookmarkedWorkIndexer, :world).enqueue_ids(group.map(&:id))
end
Bookmark.where("bookmarks.updated_at > #{time}").select(:id).find_in_batches(batch_size: BATCH_SIZE) do |group|
AsyncIndexer.new(BookmarkIndexer, :world).enqueue_ids(group.map(&:id))
end
end
desc "Reindex recent works"
task timed_works: :environment do
time = ENV["TIME_PERIOD"] || "NOW() - INTERVAL 1 DAY"
Work.where("works.revised_at > #{time}").select(:id).find_in_batches(batch_size: BATCH_SIZE) do |group|
AsyncIndexer.new(WorkIndexer, :world).enqueue_ids(group.map(&:id))
end
end
desc "Reindex recent tags"
task timed_tags: :environment do
time = ENV["TIME_PERIOD"] || "NOW() - INTERVAL 1 DAY"
Tag.where("tags.updated_at > #{time}").select(:id).find_in_batches(batch_size: BATCH_SIZE) do |group|
AsyncIndexer.new(TagIndexer, :world).enqueue_ids(group.map(&:id))
end
end
desc "Reindex pseuds"
task timed_pseud: :environment do
time = ENV["TIME_PERIOD"] || "NOW() - INTERVAL 1 DAY"
Pseud.where("pseuds.updated_at > #{time}").select(:id).find_in_batches(batch_size: BATCH_SIZE) do |group|
AsyncIndexer.new(PseudIndexer, :world).enqueue_ids(group.map(&:id))
end
end
desc "Run tasks enqueued to the world queue by IndexQueue."
task run_world_index_queue: :environment do
ScheduledReindexJob::MAIN_CLASSES.each do |klass|
IndexQueue.from_class_and_label(klass, :world).run
end
end
end