Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/api/app/controllers/search_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def search(what, render_all)

items = find_items(what, predicate)

matches = items.size
matches = items.count
if render_all && search_results_exceed_configured_limit?(matches)
render_error status: 403, errorcode: 'search_results_exceed_configured_limit', message: <<~MESSAGE.chomp
The number of results returned by the performed search exceeds the configured limit.
Expand All @@ -215,6 +215,9 @@ def search(what, render_all)
items = filter_items(items)
end

# plucking the ids for the cache and for the output
item_ids = items.pluck(:id)

opts = {}

if what == :request
Expand All @@ -230,13 +233,13 @@ def search(what, render_all)
else
"xml_id_#{what}_%d"
end
search_items = filter_items_from_cache(items, xml, key_template)
search_items = filter_items_from_cache(item_ids, xml, key_template)

search_finder = SearchFinder.new(what: what, search_items: search_items, render_all: render_all)

relation = search_finder.call

unless items.empty?
unless item_ids.empty?
relation.each do |item|
next if xml[item.id]

Expand All @@ -245,7 +248,7 @@ def search(what, render_all)
end
end

items.each do |i|
item_ids.each do |i|
output << xml[i]
end

Expand All @@ -257,8 +260,8 @@ def search(what, render_all)

def filter_items(items)
offset = params.fetch(:offset, 0).to_i
limit = params.fetch(:limit, items.size).to_i
Kaminari.paginate_array(items, limit: limit, offset: offset)
limit = params.fetch(:limit, items.count).to_i
items.offset(offset).limit(limit)
end

def group_attribute_values_by_attrib_id(values)
Expand Down
2 changes: 1 addition & 1 deletion src/api/lib/xpath_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def find(xpath)
conditions: cond_ary }.inspect}")
relation = relation.joins(@joins.flatten.uniq.join(' ')).where(cond_ary).order(order)
# .distinct is critical for perfomance here...
relation.distinct.pluck(:id)
relation.distinct
end

def parse_predicate(root, stack)
Expand Down