Skip to content

Enable to force-disable pagination per relationship #1750

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

Merged
merged 3 commits into from
Aug 2, 2025

Conversation

bkoelman
Copy link
Member

@bkoelman bkoelman commented Aug 2, 2025

In cases where the total number of resources of a certain type is high, but the number of related resources is consistently low, it becomes easier for clients to build master/detail views when they don't need to consider nested pagination.

For example, the total number of products in a web shop is typically high, but the number of products in a shopping basket is typically low. This PR enables turning off pagination for that relationship (while leaving the default page size activated):

public class Product : Identifiable<long>
{
    // ...
}

public class ShoppingBasket : Identifiable<Guid>
{
    // ...

    [HasMany(DisablePagination = true)] // <-- DisablePagination is new
    public ISet<Product> Products { get; set; } = new HashSet<Product>();
}

The effect is that pagination on products will be disabled for the following requests:

  • /shoppingBaskets?include=products
  • /shoppingBaskets/1?include=products
  • /shoppingBaskets/1/products
  • /shoppingBaskets/1/products?page[size]=25

Additionally, when pagination is set from a resource definition, it does not get applied. This is because resource definitions operate on resource types. The new property on a relationship overrules that, similar to how setting links on a relationship overrules the links defined on a resource type.

Caution

Only use this property when the set of related resources is known to be small. Take into account the full size of any nested includes.

For example, when the default page size is 50 and each basket contains 125 products, and each product contains 80 discount rules, the request /shoppingBaskets?include=products.discountRules returns a total of 50 (baskets) * 125 (products) * 50 (rules) = 312,500 resources!

Fixes #1731.

QUALITY CHECKLIST

@bkoelman bkoelman force-pushed the disable-pagination-on-relationship branch from b4835af to 196566e Compare August 2, 2025 01:05
Copy link

codecov bot commented Aug 2, 2025

Codecov Report

❌ Patch coverage is 85.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.87%. Comparing base (f4980c3) to head (913248e).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...piDotNetCore/Queries/Expressions/SortExpression.cs 62.50% 1 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1750      +/-   ##
==========================================
- Coverage   90.87%   90.87%   -0.01%     
==========================================
  Files         475      475              
  Lines       14690    14703      +13     
  Branches     2319     2324       +5     
==========================================
+ Hits        13350    13361      +11     
- Misses        911      912       +1     
- Partials      429      430       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bkoelman bkoelman force-pushed the disable-pagination-on-relationship branch from 196566e to 33591e3 Compare August 2, 2025 09:24
@bkoelman bkoelman force-pushed the disable-pagination-on-relationship branch from 33591e3 to 913248e Compare August 2, 2025 09:37
@bkoelman bkoelman marked this pull request as ready for review August 2, 2025 09:37
@bkoelman bkoelman merged commit cd8ae40 into master Aug 2, 2025
16 checks passed
@bkoelman bkoelman deleted the disable-pagination-on-relationship branch August 2, 2025 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Timeouts in include queries when using resource inheritance
1 participant