Skip to content

Commit 738820e

Browse files
committed
Merge branch 'feature/lazy-eager-indexes' into feature/ignored_allowed_groups
2 parents a572967 + d4a6971 commit 738820e

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

lib/mu_search/config_parser.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ def self.validate_composite_type(type, types)
223223
#
224224
def self.validate_eager_indexing_groups(groups)
225225
errors = []
226+
226227
groups.each do |group|
227228
unless group.kind_of?(Array)
228229
errors << "invalid eager indexing groups, each group should be an array. #{group.inspect} is not"
@@ -232,7 +233,13 @@ def self.validate_eager_indexing_groups(groups)
232233
errors << "invalid eager indexing group: #{group.inspect}."
233234
end
234235
end
236+
237+
has_wildcards = group.map { |access_right | access_right["variables"] }.flatten!.any? "*"
238+
if group.length > 1 and has_wildcards
239+
errors << "Eager indexing group with wildcard variables may contain only 1 access right. #{group.inspect} contains #{group.length}."
240+
end
235241
end
242+
236243
errors
237244
end
238245
end

lib/mu_search/index_manager.rb

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,21 @@ def initialize_indexes
162162
total = @configuration[:eager_indexing_groups].length * @configuration[:type_definitions].keys.length
163163
count = 0
164164
@configuration[:eager_indexing_groups].each do |allowed_groups|
165+
is_dynamic = allowed_groups.map { |group | group["variables"] }.flatten!.any? "*"
166+
165167
@configuration[:type_definitions].keys.each do |type_name|
166168
count = count + 1
167-
index = ensure_index(type_name, allowed_groups, [], true)
168-
@logger.info("INDEX MGMT") { "(#{count}/#{total}) Eager index #{index.name} created for type '#{index.type_name}' and allowed_groups #{allowed_groups}. Current status: #{index.status}." }
169-
if index.status == :invalid
170-
@logger.info("INDEX MGMT") { "Eager index #{index.name} not up-to-date. Start reindexing documents." }
171-
index_documents index
172-
index.status = :valid
169+
170+
if is_dynamic
171+
@logger.info("INDEX MGMT") { "(#{count}/#{total}) Eager index for type '#{type_name}' and allowed_groups #{allowed_groups} contains a dynamic segment. Index will be built with filled in pattern at search time." }
172+
else
173+
index = ensure_index(type_name, allowed_groups, [], true)
174+
@logger.info("INDEX MGMT") { "(#{count}/#{total}) Eager index #{index.name} created for type '#{index.type_name}' and allowed_groups #{allowed_groups}. Current status: #{index.status}." }
175+
if index.status == :invalid
176+
@logger.info("INDEX MGMT") { "Eager index #{index.name} not up-to-date. Start reindexing documents." }
177+
index_documents index
178+
index.status = :valid
179+
end
173180
end
174181
end
175182
end
@@ -220,8 +227,32 @@ def ensure_index_combination_for_groups(type_name, allowed_groups, used_groups =
220227
end
221228
end
222229

230+
# Create missing indexing if they are configured as eager index with '*'
231+
missing_allowed_groups = allowed_groups.reject do |allowed_group|
232+
minimal_matching_indexes.any? do |idx|
233+
idx.allowed_groups.include? allowed_group
234+
end
235+
end
236+
237+
all_missing_allowed_groups_dynamic_and_eager = missing_allowed_groups.all? do |allowed_group|
238+
@configuration[:eager_indexing_groups].any? do |eager_index_groups|
239+
# We currently assume only 1 group spec in a dynamic eager index
240+
eager_index_group = eager_index_groups.first
241+
eager_index_group["name"] == allowed_group["name"] \
242+
and eager_index_group["variables"].length == allowed_group["variables"].length \
243+
and eager_index_group["variables"].all? { |variable| variable == "*" }
244+
end
245+
end
246+
247+
if all_missing_allowed_groups_dynamic_and_eager
248+
missing_allowed_groups.each do |allowed_group|
249+
minimal_matching_indexes << ensure_index(type_name, [allowed_group], used_groups)
250+
end
251+
end
252+
223253
# Verify whether allowed_groups match is complete.
224254
# I.e. the combination of allowed groups of the matching indexes cover the given allowed_groups
255+
# Should now be equivalent to all_missing_allowed_groups_dynamic_and_eager.
225256
is_complete_match = allowed_groups.all? do |allowed_group|
226257
minimal_matching_indexes.any? do |idx|
227258
idx.allowed_groups.include? allowed_group

0 commit comments

Comments
 (0)