Browse Source

Options to specify the number of items to return.

pull/329/head
Sebastian Stehle 7 years ago
parent
commit
e880a2225c
  1. 14
      src/Squidex.Domain.Apps.Entities/Assets/AssetOptions.cs
  2. 13
      src/Squidex.Domain.Apps.Entities/Assets/AssetQueryService.cs
  3. 14
      src/Squidex.Domain.Apps.Entities/Contents/ContentOptions.cs
  4. 9
      src/Squidex.Domain.Apps.Entities/Contents/ContentQueryService.cs
  5. 7
      src/Squidex/AppServices.cs
  6. 6
      src/Squidex/Config/Domain/EntitiesServices.cs
  7. 18
      src/Squidex/appsettings.json
  8. 2
      tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetQueryServiceTests.cs
  9. 2
      tests/Squidex.Domain.Apps.Entities.Tests/Contents/ContentQueryServiceTests.cs

14
src/Squidex.Domain.Apps.Entities/Assets/AssetOptions.cs

@ -0,0 +1,14 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
namespace Squidex.Domain.Apps.Entities.Assets
{
public sealed class AssetOptions
{
public int MaxResults { get; set; } = 100;
}
}

13
src/Squidex.Domain.Apps.Entities/Assets/AssetQueryService.cs

@ -22,18 +22,19 @@ namespace Squidex.Domain.Apps.Entities.Assets
{ {
public sealed class AssetQueryService : IAssetQueryService public sealed class AssetQueryService : IAssetQueryService
{ {
private const int MaxResults = 200;
private readonly ITagService tagService; private readonly ITagService tagService;
private readonly IAssetRepository assetRepository; private readonly IAssetRepository assetRepository;
private readonly AssetOptions options;
public AssetQueryService(ITagService tagService, IAssetRepository assetRepository) public AssetQueryService(ITagService tagService, IAssetRepository assetRepository, AssetOptions options)
{ {
Guard.NotNull(tagService, nameof(tagService)); Guard.NotNull(tagService, nameof(tagService));
Guard.NotNull(options, nameof(options));
Guard.NotNull(assetRepository, nameof(assetRepository)); Guard.NotNull(assetRepository, nameof(assetRepository));
this.tagService = tagService;
this.assetRepository = assetRepository; this.assetRepository = assetRepository;
this.options = options;
this.tagService = tagService;
} }
public async Task<IAssetEntity> FindAssetAsync(QueryContext context, Guid id) public async Task<IAssetEntity> FindAssetAsync(QueryContext context, Guid id)
@ -97,9 +98,9 @@ namespace Squidex.Domain.Apps.Entities.Assets
result.Sort.Add(new SortNode(new List<string> { "lastModified" }, SortOrder.Descending)); result.Sort.Add(new SortNode(new List<string> { "lastModified" }, SortOrder.Descending));
} }
if (result.Take > MaxResults) if (result.Take > options.MaxResults)
{ {
result.Take = MaxResults; result.Take = options.MaxResults;
} }
return result; return result;

14
src/Squidex.Domain.Apps.Entities/Contents/ContentOptions.cs

@ -0,0 +1,14 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
namespace Squidex.Domain.Apps.Entities.Contents
{
public sealed class ContentOptions
{
public int MaxResults { get; set; } = 100;
}
}

9
src/Squidex.Domain.Apps.Entities/Contents/ContentQueryService.cs

@ -28,7 +28,6 @@ namespace Squidex.Domain.Apps.Entities.Contents
{ {
public sealed class ContentQueryService : IContentQueryService public sealed class ContentQueryService : IContentQueryService
{ {
private const int MaxResults = 200;
private static readonly Status[] StatusAll = { Status.Archived, Status.Draft, Status.Published }; private static readonly Status[] StatusAll = { Status.Archived, Status.Draft, Status.Published };
private static readonly Status[] StatusArchived = { Status.Archived }; private static readonly Status[] StatusArchived = { Status.Archived };
private static readonly Status[] StatusPublished = { Status.Published }; private static readonly Status[] StatusPublished = { Status.Published };
@ -37,6 +36,7 @@ namespace Squidex.Domain.Apps.Entities.Contents
private readonly IContentVersionLoader contentVersionLoader; private readonly IContentVersionLoader contentVersionLoader;
private readonly IAppProvider appProvider; private readonly IAppProvider appProvider;
private readonly IScriptEngine scriptEngine; private readonly IScriptEngine scriptEngine;
private readonly ContentOptions options;
private readonly EdmModelBuilder modelBuilder; private readonly EdmModelBuilder modelBuilder;
public ContentQueryService( public ContentQueryService(
@ -44,18 +44,21 @@ namespace Squidex.Domain.Apps.Entities.Contents
IContentRepository contentRepository, IContentRepository contentRepository,
IContentVersionLoader contentVersionLoader, IContentVersionLoader contentVersionLoader,
IScriptEngine scriptEngine, IScriptEngine scriptEngine,
ContentOptions options,
EdmModelBuilder modelBuilder) EdmModelBuilder modelBuilder)
{ {
Guard.NotNull(appProvider, nameof(appProvider)); Guard.NotNull(appProvider, nameof(appProvider));
Guard.NotNull(contentRepository, nameof(contentRepository)); Guard.NotNull(contentRepository, nameof(contentRepository));
Guard.NotNull(contentVersionLoader, nameof(contentVersionLoader)); Guard.NotNull(contentVersionLoader, nameof(contentVersionLoader));
Guard.NotNull(modelBuilder, nameof(modelBuilder)); Guard.NotNull(modelBuilder, nameof(modelBuilder));
Guard.NotNull(options, nameof(options));
Guard.NotNull(scriptEngine, nameof(scriptEngine)); Guard.NotNull(scriptEngine, nameof(scriptEngine));
this.appProvider = appProvider; this.appProvider = appProvider;
this.contentRepository = contentRepository; this.contentRepository = contentRepository;
this.contentVersionLoader = contentVersionLoader; this.contentVersionLoader = contentVersionLoader;
this.modelBuilder = modelBuilder; this.modelBuilder = modelBuilder;
this.options = options;
this.scriptEngine = scriptEngine; this.scriptEngine = scriptEngine;
} }
@ -214,9 +217,9 @@ namespace Squidex.Domain.Apps.Entities.Contents
result.Sort.Add(new SortNode(new List<string> { "lastModified" }, SortOrder.Descending)); result.Sort.Add(new SortNode(new List<string> { "lastModified" }, SortOrder.Descending));
} }
if (result.Take > MaxResults) if (result.Take > options.MaxResults)
{ {
result.Take = MaxResults; result.Take = options.MaxResults;
} }
return result; return result;

7
src/Squidex/AppServices.cs

@ -14,6 +14,8 @@ using Squidex.Config;
using Squidex.Config.Authentication; using Squidex.Config.Authentication;
using Squidex.Config.Domain; using Squidex.Config.Domain;
using Squidex.Config.Web; using Squidex.Config.Web;
using Squidex.Domain.Apps.Entities.Assets;
using Squidex.Domain.Apps.Entities.Contents;
using Squidex.Extensions.Actions.Twitter; using Squidex.Extensions.Actions.Twitter;
using Squidex.Infrastructure.Commands; using Squidex.Infrastructure.Commands;
@ -44,9 +46,12 @@ namespace Squidex
services.AddMySwaggerSettings(); services.AddMySwaggerSettings();
services.AddMySubscriptionServices(config); services.AddMySubscriptionServices(config);
services.Configure<ContentOptions>(
config.GetSection("contents"));
services.Configure<AssetOptions>(
config.GetSection("assets"));
services.Configure<ReadonlyOptions>( services.Configure<ReadonlyOptions>(
config.GetSection("mode")); config.GetSection("mode"));
services.Configure<TwitterOptions>( services.Configure<TwitterOptions>(
config.GetSection("twitter")); config.GetSection("twitter"));

6
src/Squidex/Config/Domain/EntitiesServices.cs

@ -65,9 +65,15 @@ namespace Squidex.Config.Domain
services.AddSingletonAs<AppProvider>() services.AddSingletonAs<AppProvider>()
.As<IAppProvider>(); .As<IAppProvider>();
services.AddSingletonAs(c => c.GetRequiredService<IOptions<AssetOptions>>().Value)
.AsSelf();
services.AddSingletonAs<AssetQueryService>() services.AddSingletonAs<AssetQueryService>()
.As<IAssetQueryService>(); .As<IAssetQueryService>();
services.AddSingletonAs(c => c.GetRequiredService<IOptions<ContentOptions>>().Value)
.AsSelf();
services.AddSingletonAs<ContentQueryService>() services.AddSingletonAs<ContentQueryService>()
.As<IContentQueryService>(); .As<IContentQueryService>();

18
src/Squidex/appsettings.json

@ -63,6 +63,24 @@
"maxItemsForSurrogateKeys": 200 "maxItemsForSurrogateKeys": 200
}, },
"content": {
/*
* The maximum number of items to return for each query.
*
* Warning: Use pagination and not large number of items.
*/
"maxResults": 200
},
"assets": {
/*
* The maximum number of items to return for each query.
*
* Warning: Use pagination and not large number of items.
*/
"maxResults": 200
},
"logging": { "logging": {
/* /*
* Setting the flag to true, enables well formatteds json logs. * Setting the flag to true, enables well formatteds json logs.

2
tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetQueryServiceTests.cs

@ -49,7 +49,7 @@ namespace Squidex.Domain.Apps.Entities.Assets
["id3"] = "name3" ["id3"] = "name3"
}); });
sut = new AssetQueryService(tagService, assetRepository); sut = new AssetQueryService(tagService, assetRepository, new AssetOptions());
} }
[Fact] [Fact]

2
tests/Squidex.Domain.Apps.Entities.Tests/Contents/ContentQueryServiceTests.cs

@ -60,7 +60,7 @@ namespace Squidex.Domain.Apps.Entities.Contents
context = new ContentQueryContext(QueryContext.Create(app, user)); context = new ContentQueryContext(QueryContext.Create(app, user));
sut = new ContentQueryService(appProvider, contentRepository, contentVersionLoader, scriptEngine, modelBuilder); sut = new ContentQueryService(appProvider, contentRepository, contentVersionLoader, scriptEngine, new ContentOptions(), modelBuilder);
} }
[Fact] [Fact]

Loading…
Cancel
Save