From 4a60e674cfb1b56b6de1e0b8dad4be629c605562 Mon Sep 17 00:00:00 2001 From: Hung Nguyen Date: Tue, 4 Jun 2024 14:27:35 +0700 Subject: [PATCH] fix: Search with paging when using validElements API --- VERSION | 2 +- lib/gooddata/models/metadata/label.rb | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index 547c23c55..5c2e2531a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.7.66 +3.7.67 diff --git a/lib/gooddata/models/metadata/label.rb b/lib/gooddata/models/metadata/label.rb index 2dd9f8e33..2b106bb4b 100644 --- a/lib/gooddata/models/metadata/label.rb +++ b/lib/gooddata/models/metadata/label.rb @@ -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