app/models/apidae/selection.rb in apidae-1.3.2 vs app/models/apidae/selection.rb in apidae-1.3.3
- old
+ new
@@ -67,11 +67,11 @@
def api_agenda(from, to)
key = cache_key(:agenda, from, to)
res = $apidae_cache.read(key)
unless res
- query_args = build_args(AGENDA_ENDPOINT, {selection_ids: [apidae_id], from: from, to: to})
+ query_args = build_args(AGENDA_ENDPOINT, {selection_ids: [apidae_id], from: from, to: to, count: 200})
res = query_api(query_args, true)
$apidae_cache.write(key, res)
end
res
end
@@ -140,17 +140,18 @@
def query_api(query_args, all_results = false, only_ids = true)
query_result = {}
if all_results
loops = 0
+ max_loops = only_ids ? 50 : MAX_LOOPS
query_args[:first] = 0
- query_args[:count] = MAX_COUNT
+ query_args[:count] ||= MAX_COUNT
query_args[:locales] ||= apidae_project && !apidae_project.locales.blank? ? apidae_project.locales : [DEFAULT_LOCALE]
response = JSON.parse get_response(query_args), symbolize_names: false
total = response['numFound']
query_result[:results] = (only_ids ? response['objetTouristiqueIds'] : response['objetsTouristiques']) || {}
- while total > results_count(query_result) && loops < MAX_LOOPS
+ while total > results_count(query_result) && loops < max_loops
loops += 1
query_args[:first] += MAX_COUNT
response = JSON.parse get_response(query_args), symbolize_names: false
if only_ids
merge_results(response, query_result)