Browse Source

Do not apply default page size for id queries.

pull/768/head
Sebastian 4 years ago
parent
commit
9bb1ca87f8
  1. 15
      backend/src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetQueryParser.cs
  2. 15
      backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentQueryParser.cs
  3. 13
      backend/src/Squidex/Areas/IdentityServer/Views/Setup/Webpack.cshtml
  4. 7
      backend/src/Squidex/wwwroot/styles/bootstrap.min.css
  5. 33
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/Queries/AssetQueryParserTests.cs
  6. 32
      backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ContentQueryParserTests.cs

15
backend/src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetQueryParser.cs

@ -54,7 +54,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries
await TransformTagAsync(context, query);
WithSorting(query);
WithPaging(query);
WithPaging(query, q);
q = q.WithQuery(query);
@ -83,11 +83,18 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries
return query;
}
private void WithPaging(ClrQuery query)
private void WithPaging(ClrQuery query, Q q)
{
if (query.Take == long.MaxValue)
if (query.Take <= 0 || query.Take == long.MaxValue)
{
query.Take = options.DefaultPageSize;
if (q.Ids != null && q.Ids.Count > 0)
{
query.Take = q.Ids.Count;
}
else
{
query.Take = options.DefaultPageSize;
}
}
else if (query.Take > options.MaxResults)
{

15
backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentQueryParser.cs

@ -65,7 +65,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries
await TransformFilterAsync(query, context, schema);
WithSorting(query);
WithPaging(query);
WithPaging(query, q);
q = q.WithQuery(query);
@ -155,11 +155,18 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries
}
}
private void WithPaging(ClrQuery query)
private void WithPaging(ClrQuery query, Q q)
{
if (query.Take == long.MaxValue)
if (query.Take <= 0 || query.Take == long.MaxValue)
{
query.Take = options.DefaultPageSize;
if (q.Ids != null && q.Ids.Count > 0)
{
query.Take = q.Ids.Count;
}
else
{
query.Take = options.DefaultPageSize;
}
}
else if (query.Take > options.MaxResults)
{

13
backend/src/Squidex/Areas/IdentityServer/Views/Setup/Webpack.cshtml

@ -14,7 +14,7 @@
<title>@ViewBag.Title - @T.Get("common.product")</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="@Url.RootContentUrl("~/styles/bootstrap.min.css")" rel="stylesheet">
<style>
body {
background: #f5f6f9;
@ -43,6 +43,10 @@
font-weight: normal;
margin-top: 2rem;
}
.card-body {
text-align: center;
}
</style>
</head>
<body class="profile">
@ -55,12 +59,9 @@
<h1 class="splash-h1">@T.Get("setup.webpack.headline")</h1>
<p class="splash-text">
<span>@T.Get("setup.webpack.text")</span>
<a href="https://docs.squidex.io/01-getting-started/contributing-and-developing/developing" target="_blank">@T.Get("common.documentation")</a>
</p>
<p>@T.Get("setup.webpack.text")</p>
<a href="https://docs.squidex.io/01-getting-started/contributing-and-developing/developing" target="_blank">@T.Get("common.documentation")</a>
</div>
</div>

7
backend/src/Squidex/wwwroot/styles/bootstrap.min.css

File diff suppressed because one or more lines are too long

33
backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/Queries/AssetQueryParserTests.cs

@ -13,6 +13,7 @@ using Squidex.Domain.Apps.Core.Tags;
using Squidex.Domain.Apps.Core.TestHelpers;
using Squidex.Domain.Apps.Entities.TestHelpers;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Queries;
using Squidex.Infrastructure.Validation;
using Xunit;
@ -98,10 +99,14 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries
Assert.Equal("FullText: 'Hello'; Take: 30; Sort: lastModified Descending, id Ascending", q.Query.ToString());
}
[Fact]
public async Task Should_apply_default_page_size()
[Theory]
[InlineData(0L)]
[InlineData(-1L)]
[InlineData(long.MaxValue)]
[InlineData(long.MinValue)]
public async Task Should_apply_default_take_size_if_not_defined(long take)
{
var query = Q.Empty;
var query = Q.Empty.WithQuery(new ClrQuery { Take = take });
var q = await sut.ParseAsync(requestContext, query);
@ -109,7 +114,27 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries
}
[Fact]
public async Task Should_apply_default_limit()
public async Task Should_set_take_to_ids_count_if_take_not_defined()
{
var query = Q.Empty.WithIds("1, 2, 3");
var q = await sut.ParseAsync(requestContext, query);
Assert.Equal("Take: 3; Sort: lastModified Descending, id Ascending", q.Query.ToString());
}
[Fact]
public async Task Should_not_set_take_to_ids_count_if_take_defined()
{
var query = Q.Empty.WithIds("1, 2, 3").WithQuery(new ClrQuery { Take = 20 });
var q = await sut.ParseAsync(requestContext, query);
Assert.Equal("Take: 20; Sort: lastModified Descending, id Ascending", q.Query.ToString());
}
[Fact]
public async Task Should_apply_default_take_limit()
{
var query = Q.Empty.WithODataQuery("$top=300&$skip=20");

32
backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ContentQueryParserTests.cs

@ -243,10 +243,14 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries
Assert.Equal("Filter: id == '__notfound__'; Take: 30; Sort: lastModified Descending, id Ascending", q.Query.ToString());
}
[Fact]
public async Task Should_apply_default_page_size()
[Theory]
[InlineData(0L)]
[InlineData(-1L)]
[InlineData(long.MaxValue)]
[InlineData(long.MinValue)]
public async Task Should_apply_default_take_size_if_not_defined(long take)
{
var query = Q.Empty;
var query = Q.Empty.WithQuery(new ClrQuery { Take = take });
var q = await sut.ParseAsync(requestContext, query, schema);
@ -254,7 +258,27 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries
}
[Fact]
public async Task Should_apply_default_limit()
public async Task Should_set_take_to_ids_count_if_take_not_defined()
{
var query = Q.Empty.WithIds("1, 2, 3");
var q = await sut.ParseAsync(requestContext, query, schema);
Assert.Equal("Take: 3; Sort: lastModified Descending, id Ascending", q.Query.ToString());
}
[Fact]
public async Task Should_not_set_take_to_ids_count_if_take_defined()
{
var query = Q.Empty.WithIds("1, 2, 3").WithQuery(new ClrQuery { Take = 20 });
var q = await sut.ParseAsync(requestContext, query, schema);
Assert.Equal("Take: 20; Sort: lastModified Descending, id Ascending", q.Query.ToString());
}
[Fact]
public async Task Should_apply_default_take_limit()
{
var query = Q.Empty.WithODataQuery("$top=300&$skip=20");

Loading…
Cancel
Save