From c313649237563f76855733b809f8db2a27d0cb50 Mon Sep 17 00:00:00 2001 From: Sergey Litvinov Date: Mon, 21 Oct 2019 16:01:58 +0300 Subject: [PATCH] removed automatic TotalResultsCount filling based on IQueryable\IEnumerable and removed 1 unit test that covered that --- Saule/Queries/Pagination/PaginationInterpreter.cs | 12 ------------ Tests/Integration/JsonApiMediaTypeFormatterTests.cs | 1 - 2 files changed, 13 deletions(-) diff --git a/Saule/Queries/Pagination/PaginationInterpreter.cs b/Saule/Queries/Pagination/PaginationInterpreter.cs index bed5b3c..b11acdb 100644 --- a/Saule/Queries/Pagination/PaginationInterpreter.cs +++ b/Saule/Queries/Pagination/PaginationInterpreter.cs @@ -24,13 +24,6 @@ public IQueryable Apply(IQueryable queryable) .Where(i => i.IsGenericType) .Any(i => i.GetGenericTypeDefinition() == typeof(IOrderedQueryable<>)); - // if we don't have totalResultsCount in the context - // then we will try to get it from IQueryable by executing one more query before Order\Skip\Take - if (!_context.TotalResultsCount.HasValue && _context.PerPage.GetValueOrDefault() != 0) - { - _context.TotalResultsCount = (int)queryable.ApplyQuery(QueryMethod.Count); - } - var ordered = isOrdered ? queryable : OrderById(queryable); var filtered = ordered.ApplyQuery(QueryMethod.Skip, _context.Page * _context.PerPage) as IQueryable; @@ -41,11 +34,6 @@ public IQueryable Apply(IQueryable queryable) public IEnumerable Apply(IEnumerable queryable) { - if (!_context.TotalResultsCount.HasValue && _context.PerPage.GetValueOrDefault() != 0) - { - _context.TotalResultsCount = (int)queryable.ApplyQuery(QueryMethod.Count); - } - var filtered = queryable.ApplyQuery(QueryMethod.Skip, _context.Page * _context.PerPage) as IEnumerable; filtered = filtered.ApplyQuery(QueryMethod.Take, _context.PerPage) as IEnumerable; diff --git a/Tests/Integration/JsonApiMediaTypeFormatterTests.cs b/Tests/Integration/JsonApiMediaTypeFormatterTests.cs index f186081..9da553c 100644 --- a/Tests/Integration/JsonApiMediaTypeFormatterTests.cs +++ b/Tests/Integration/JsonApiMediaTypeFormatterTests.cs @@ -435,7 +435,6 @@ public async Task LimitsPageSizeIsNotSet() [InlineData("api/companies/paged-result", 0)] [InlineData("api/companies/paged-result-first-page", 1)] - [InlineData("api/companies/paged-result-queryable", 0)] [Theory(DisplayName = "Paged result calculates page counts")] public async Task PagedResult(object baseUrl, int firstPageNumber) {