Fix: auto-flatten paged /users responses; slim User attributes#55
Merged
Fix: auto-flatten paged /users responses; slim User attributes#55
Conversation
…github.com/ontoportal-lirmm/ontologies_api_ruby_client into ontoportal-lirmm-pr/feautre/add-multiple-media-types-models
…dels' into develop
Pairs with the ontologies_api /users pagination change. Two changes that together let existing callers of `LinkedData::Client::Models::User.all` keep working without code changes after the API switches to mandatory pagination. Collection#all detects paged responses (collection/pageCount/nextPage shape) and walks `nextPage` links transparently, returning a flat Array. Falls through to existing behavior when the response is already an Array (pre-pagination back-compat) or when the caller explicitly requested a `:page` (passthrough). Internal pagesize: 5_000 to minimize request count. Models::User defaults to a slim `@include_attrs` allow-list (username, email, role, firstName, lastName, created) instead of "all", and overrides `.all` to inject `display_context: false, display_links: false`. Drops the heavy User payload (custom ontologies, tokens, hashes, JSON-LD context, HATEOAS links) for list/select use cases. Adds Collection tests for paged-flatten, page-passthrough, and User.all slim-defaults.
Manual benchmark harness for the /users endpoint. Times two paths (raw Net::HTTP and Models::User.all) plus an optional --page=N --pagesize=M single-page mode for isolating per-page cost without the all-pages walk. Used to verify the ontologies_api + ontologies_linked_data#286 fixes against the production timeout issue. Not loaded by the test suite; invoked manually via: UT_APIKEY=<key> bundle exec ruby test/benchmark/users.rb
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #55 +/- ##
==========================================
+ Coverage 66.48% 68.34% +1.86%
==========================================
Files 29 29
Lines 919 973 +54
Branches 174 188 +14
==========================================
+ Hits 611 665 +54
Misses 308 308
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Per PR review feedback: the back-compat invariant for non-paginated endpoints (e.g. /ontologies, /groups, /categories today) is currently only exercised implicitly by the network-dependent `test_all`. If we ever paginate one of those endpoints, that test would silently switch to exercising the paged path instead, leaving the Array passthrough uncovered. Adds test_all_passes_through_array_response — stubs entry_point to return a flat Array and asserts Collection#all returns it unchanged. Also asserts pagesize: 5_000 is still injected on the request (the API simply ignores it on non-paginated endpoints).
5 tasks
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
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.
PR description
Summary
Collection#alldetects paged API responses (collection/pageCount/nextPageshape) and walksnextPagelinks transparently, returning a flat Array. Pre-pagination Array responses pass through unchanged. Internalpagesize: 5_000to minimize request count.Models::Userdefaults to a slim@include_attrsallow-list (username, email, role, firstName, lastName, created) instead of"all", and overrides.allto injectdisplay_context: false, display_links: false. Drops the heavy User payload (custom ontologies, tokens, hashes, JSON-LD context) for list/select use cases.test/benchmark/users.rbharness for reproducing and quantifying the production timeout (not loaded by the test suite — invoked manually withUT_APIKEY=… bundle exec rubytest/benchmark/users.rb).Why
Production users were unable to create ontologies, with
Faraday::TimeoutErrorfrombioportal_web_uicontrollers callingLinkedData::Client::Models::User.all. The fix spans four repos:User#admin?, drop inverse attrs from auth loadfix/slow-users-endpointPR — mandatory pagination onGET /users(+ a related/searchand/property_search500 fix)This client release is what makes the ontologies_api breaking change (mandatory pagination) transparent to existing in-process callers.
Backward / forward compatibility
paged_collection?false)nextPage, returns flat Array:pageexplicitlyTest plan
UT_APIKEY=<key> bundle exec rake test TEST="./test/models/test_collection.rb"— three new tests pass:test_all_flattens_paged_collections,test_all_returns_page_when_page_requested,test_user_all_uses_lightweight_defaults. Existingtest_all,test_class_for_type,test_wherecontinue to pass.test_findandtest_find_bywill fail when run against a local API — they hard-codehttps://data.bioontology.org/...URIs while a local triplestore storeshttp://localhost:9393/.... Pre-existing issue (introduced 2023-07-19, not a regression from this PR). Worth a separate cleanup ticket.UT_APIKEY=<key> bundle exec ruby test/benchmark/users.rbreports per-page and full-walk timings consistent with the table above.Models::User.allreturns a flat Array;Models::User.all(page: 1)returns a paged response object;Models::Ontology.allcontinues to returna flat Array unchanged.