Skip to content

Feat: added metadata on pagination responses#115

Merged
csantero merged 3 commits intoJSONAPIdotNET:masterfrom
spike83:pagination-metadata
Sep 15, 2016
Merged

Feat: added metadata on pagination responses#115
csantero merged 3 commits intoJSONAPIdotNET:masterfrom
spike83:pagination-metadata

Conversation

@spike83
Copy link
Contributor

@spike83 spike83 commented Aug 8, 2016

  • metadata to indicate the count of pages and total count of records
  • acceptance tests pagination in combination with filters and sorting

@csantero
Copy link
Collaborator

csantero commented Aug 9, 2016

@spike83 I think it would be better to move these changes into a derived class in the JSONAPI.EntityFramework project. Then we don't introduce any unwanted behavior changes in the default implementation of IQueryableResourceCollectionBuilder, and you will be able to use CountAsync, because the async LINQ methods require EntityFramework.

I also noticed you are calling Count twice on filteredQuery. This should be combined into one call so as to save a round-trip to the database.

@spike83
Copy link
Contributor Author

spike83 commented Aug 9, 2016

Thanks for your feedback. I'll improve that.

@spike83 spike83 force-pushed the pagination-metadata branch 2 times, most recently from 20825a1 to 370365b Compare August 18, 2016 06:22
writer.WritePropertyName(MetaKeyName);
MetadataFormatter.Serialize(document.Metadata, writer);
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

@spike83 is it necessary to move the metadata in the JSON document?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it's not functionally necessary. But the specs and most samples start with the top-level metadata. I haven't seen any constarint which would enforce it.
Should I move it back?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@spike83 No, it's fine.

@csantero
Copy link
Collaborator

@spike83 Merging the other PR introduced some conflicts here.

@spike83
Copy link
Contributor Author

spike83 commented Sep 12, 2016

@csantero i will fix them

- metadata to indicate the count of pages and total count of records
- acceptance tests pagination in combination with filters and sorting
reduced the number of count calls to save roundtrips
@spike83 spike83 force-pushed the pagination-metadata branch from 06efe26 to eaea639 Compare September 12, 2016 18:26
@spike83
Copy link
Contributor Author

spike83 commented Sep 12, 2016

@csantero rebased to your master

{
var count = filteredQuery.CountAsync(cancellationToken);
metadata.MetaObject.Add("total-pages", (int)Math.Ceiling((decimal) await count / paginationResult.PageSize));
metadata.MetaObject.Add("total-count", await count);
Copy link
Collaborator

Choose a reason for hiding this comment

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

@spike83 By using two awaits this will cause the exact same query to run twice. You should move the await to line 46.

@spike83
Copy link
Contributor Author

spike83 commented Sep 14, 2016

@csantero is this now ok for merging?

@csantero csantero merged commit 4374719 into JSONAPIdotNET:master Sep 15, 2016
@csantero
Copy link
Collaborator

Thanks

@spike83 spike83 deleted the pagination-metadata branch September 16, 2016 07:44
ClintGood added a commit to ClintGood/JSONAPI.NET that referenced this pull request Sep 17, 2016
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