-
Notifications
You must be signed in to change notification settings - Fork 80
Non-ActiveRecord paginator support #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gaorlov
wants to merge
10
commits into
tiagopog:master
Choose a base branch
from
gaorlov:non_ar_paginator_support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
updating testing instructions to run all the tests
Moving counting logic into (.*)Counter classes to allow for extensibility Moving countind delegation into RecordCounter class to allow for a single entrypoint
Passing params into RecordCounters to allow them to do complex counting based on the query
moving filter application out of *Counter classes due to scoping issues
updating instructions to run tests
allowing apply_sort to fall through with no modifications for unexpected result sets
fixing RecordCounter.count to pass request params into the counter classes
@tiagopog, I would love some feedback on this. |
@tiagopog bump? |
@tiagopog have you had a chance to look at this at all? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First and foremost: thanks so much for putting this gem out here!
Problem Statement
I have a service that uses
Elasticsearch
instead ofActiveRecord
and I would like to return the result set counts. BecauseActiveRecord::Relation
is referenced directly in the counting method, the app explodes. Under the current implementation, my options are to:Pagination.count_records
in every Elasticsearch-backed service I writejsonapi_render
viaoptions[:count]
Option one is really a strawman, and it felt odd to sprinkle
options: { count: MyEsModel.count( params ) }
in every single controller action across multiple controllers in several projects.Proposed Contribution
I extracted the underlying counting interface in to a
RecordCounter
module that responds tocount( records, params = {}, options ={} )
and loops through dedicatedCounter
classes that know how to count a specific class type. So like,ActiveRecord::Relation
objects go to theActiveRecordCounter
andArray
s go to theArrayCounter
class.The
#{Type}Counter
classes register themselves withRecordCounter
on declaration withcounts #{Type.to_s.underscore}
making adding new counters as easy as just declaring them in your project.What this does
I will admit that this is a somewhat involved change, but there are several benefits to this added complexity. It:
ActiveRecord::Relation
in the counting mechanismJSONAPI::Utils
Example
To use my use case, an Elasticsearch-backed system would implement a counter approximately like so: