Skip to content

Commit

Permalink
fix: Search with paging when using validElements API
Browse files Browse the repository at this point in the history
  • Loading branch information
hung-nguyen-hoang committed Jun 5, 2024
1 parent 693bd8a commit 4a60e67
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 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

0 comments on commit 4a60e67

Please sign in to comment.