Skip to content
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

Fixes #259 - Implements is_first_version and is_last_version attributes #287

Merged
merged 6 commits into from
Apr 26, 2016

Conversation

atruskie
Copy link
Member

Adds virtual fields is_first_version and is_last_version to the
Scripts API. Does NOT implement the /groups API endpoint - unnecessary
at this time.

Note one unit test currently fails because #286 is not implemented.

Adds virtual fields `is_first_version` and `is_last_version` to the
Scripts API. Does NOT implement the `/groups` API endpoint - unnecessary
at this time.
# HACK: reload item - this is a poor version of Persistence::reload
# https://github.com/rails/rails/blob/1f98eb60e59f4f70ef66ac2454ad029f46e3b27c/activerecord/lib/active_record/persistence.rb#L432
# The only difference is the `unscoped` method is removed.
def reload(options = nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

Because of scoped query needs to be count(:all)
@atruskie
Copy link
Member Author

So I'm reviewing the changes in 0ab8f91.

Converting the last_version and first_version properties to queries only is pretty bad for performance. A GET /scripts goes from 1 database query to 2×N + 1 queries - and that's ignoring the paging query! Essentially, the values in the default scope never get used.

Please consider the changes in 8bc7cb2 which use the attribute values if they are present and query for them in the rare case they are not present.

@cofiem
Copy link
Contributor

cofiem commented Apr 26, 2016

That looks reasonable - have you tested your most recent change much?

@atruskie
Copy link
Member Author

Unit and integration tests pass. Basic tests with http endpoint tester behave as I expect for index, show, and filter (with a is_last_version filter). index also works with ?filter_is_last_version=true usecase.

@cofiem
Copy link
Contributor

cofiem commented Apr 26, 2016

cool, I'll review and merge tonight

@cofiem cofiem merged commit 76e034e into develop Apr 26, 2016
@cofiem cofiem deleted the script-group-by branch April 27, 2016 03:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants