Skip to content

Commit

Permalink
Merge pull request gooddata#1972 from hung-nguyen-hoang/STL-535
Browse files Browse the repository at this point in the history
fix: Search with paging when using validElements API
  • Loading branch information
hung-nguyen-hoang authored Jun 11, 2024
2 parents f184995 + 0f95557 commit 452d446
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.7.66
3.7.67
25 changes: 21 additions & 4 deletions lib/gooddata/models/metadata/label.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,31 @@ def find_element_value(element_id)
# In the case filter a specific value, because the API /validElements only filter by partial match, we need to filter again at client side for exact match.
# @return [Array] Results
def get_valid_elements(*args)
results = {}
if args && !args.empty? && args.first[:filter]
# Support paging in case filter by a specific value
params = args.first
params[:limit] = 100_000
results, = valid_elements params
results['validElements']['items'] = results['validElements']['items'].select do |i|
i['element']['title'] == params[:filter]
all_valid_elements = []
offset = 0
paging_limit = 10_000

loop do
params[:offset] = offset
params[:limit] = paging_limit
results, = valid_elements params
all_valid_elements << results['validElements']['items'].select do |i|
i['element']['title'] == params[:filter]
end

if results['validElements']['items'].count < paging_limit
results['validElements']['items'] = all_valid_elements
break
else
offset += paging_limit
end
end
else
# This case will support paging by the method which call this method eg: values(...) method
results, = valid_elements(*args)
end
results
Expand Down
3 changes: 2 additions & 1 deletion lib/gooddata/models/user_filters/user_filter_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ def self.create_label_cache(result, options = {})

def self.create_lookups_cache(small_labels)
small_labels.reduce({}) do |a, e|
lookup = e.values(:limit => 1_000_000).reduce({}) do |a1, e1|
# The validElements API allow maximum paging with 10000 items
lookup = e.values(:limit => 10_000).reduce({}) do |a1, e1|
a1[e1[:value]] = e1[:uri]
a1
end
Expand Down

0 comments on commit 452d446

Please sign in to comment.