Skip to content

Pass fetched records to paginator instance when building links#999

Merged
lgebhardt merged 1 commit intoJSONAPI-Resources:release-0-9from
thiagorp:support-for-paginators-without-count-0-9
Mar 23, 2017
Merged

Pass fetched records to paginator instance when building links#999
lgebhardt merged 1 commit intoJSONAPI-Resources:release-0-9from
thiagorp:support-for-paginators-without-count-0-9

Conversation

@thiagorp
Copy link
Copy Markdown
Contributor

@thiagorp thiagorp commented Mar 9, 2017

I had a problem recently that the count queries that were made by the processor (https://github.com/cerebris/jsonapi-resources/blob/master/lib/jsonapi/processor.rb#L88) were taking too long. These queries become very expensive as data grows. Because of this, my service was responding really slowly and the requests were piling up.

To solve that, I created a paginator that never returns the last key and calculates if there is a next page by checking if the amount of fetched resources is greater than or equal the page size. Like this:

if options[:fetched_records].size >= @size
  links_page_params['next'] = {
    'number' => @number + 1,
    'size' => @size
  }
end

But for that I need to know how many records were fetched, and with the current implementation I don't have this information. Without this information is impossible to create paginators that don't rely on the resource_count.

(Same as #997)

@lgebhardt lgebhardt merged commit 13f6423 into JSONAPI-Resources:release-0-9 Mar 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants