Browse Source

Options for surrogate keys.

pull/303/head
Sebastian 8 years ago
parent
commit
b5437f4010
  1. 3
      src/Squidex/AppServices.cs
  2. 25
      src/Squidex/Areas/Api/Controllers/Contents/ContentsController.cs
  3. 16
      src/Squidex/Areas/Api/Controllers/Contents/ContentsControllerOptions.cs
  4. 2
      src/Squidex/WebStartup.cs
  5. 14
      src/Squidex/appsettings.json

3
src/Squidex/AppServices.cs

@ -8,6 +8,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Squidex.Areas.Api.Config.Swagger;
using Squidex.Areas.Api.Controllers.Contents;
using Squidex.Areas.IdentityServer.Config;
using Squidex.Config;
using Squidex.Config.Authentication;
@ -43,6 +44,8 @@ namespace Squidex
services.Configure<ReadonlyOptions>(
config.GetSection("mode"));
services.Configure<ContentsControllerOptions>(
config.GetSection("contentsController"));
services.Configure<MyUrlsOptions>(
config.GetSection("urls"));
services.Configure<MyIdentityOptions>(

25
src/Squidex/Areas/Api/Controllers/Contents/ContentsController.cs

@ -10,6 +10,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using NodaTime;
using NodaTime.Text;
using NSwag.Annotations;
@ -29,15 +30,18 @@ namespace Squidex.Areas.Api.Controllers.Contents
[SwaggerIgnore]
public sealed class ContentsController : ApiController
{
private readonly IOptions<ContentsControllerOptions> controllerOptions;
private readonly IContentQueryService contentQuery;
private readonly IGraphQLService graphQl;
public ContentsController(ICommandBus commandBus,
IContentQueryService contentQuery,
IGraphQLService graphQl)
IGraphQLService graphQl,
IOptions<ContentsControllerOptions> controllerOptions)
: base(commandBus)
{
this.contentQuery = contentQuery;
this.controllerOptions = controllerOptions;
this.graphQl = graphQl;
}
@ -121,7 +125,12 @@ namespace Squidex.Areas.Api.Controllers.Contents
Items = result.Take(200).Select(x => ContentDto.FromContent(x, context)).ToArray()
};
Response.Headers["Surrogate-Key"] = string.Join(" ", response.Items.Select(x => x.Id));
var options = controllerOptions.Value;
if (options.EnableSurrogateKeys && response.Items.Length <= options.MaxItemsForSurrogateKeys)
{
Response.Headers["Surrogate-Key"] = string.Join(" ", response.Items.Select(x => x.Id));
}
return Ok(response);
}
@ -151,7 +160,11 @@ namespace Squidex.Areas.Api.Controllers.Contents
var response = ContentDto.FromContent(content, context);
Response.Headers["ETag"] = content.Version.ToString();
Response.Headers["Surrogate-Key"] = content.Id.ToString();
if (controllerOptions.Value.EnableSurrogateKeys)
{
Response.Headers["Surrogate-Key"] = content.Id.ToString();
}
return Ok(response);
}
@ -183,7 +196,11 @@ namespace Squidex.Areas.Api.Controllers.Contents
var response = ContentDto.FromContent(content, context);
Response.Headers["ETag"] = content.Version.ToString();
Response.Headers["Surrogate-Key"] = content.Id.ToString();
if (controllerOptions.Value.EnableSurrogateKeys)
{
Response.Headers["Surrogate-Key"] = content.Id.ToString();
}
return Ok(response.Data);
}

16
src/Squidex/Areas/Api/Controllers/Contents/ContentsControllerOptions.cs

@ -0,0 +1,16 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
namespace Squidex.Areas.Api.Controllers.Contents
{
public sealed class ContentsControllerOptions
{
public bool EnableSurrogateKeys { get; set; }
public int MaxItemsForSurrogateKeys { get; set; }
}
}

2
src/Squidex/WebStartup.cs

@ -46,6 +46,8 @@ namespace Squidex
app.ApplicationServices.RunMigrate();
app.ApplicationServices.RunRunnables();
app.UseDeveloperExceptionPage();
app.UseMyLocalCache();
app.UseMyCors();
app.UseMyForwardingRules();

14
src/Squidex/appsettings.json

@ -49,6 +49,20 @@
}
},
"contentsController": {
/*
* Enable surrogate keys as headers.
*
* Nginx Has problems with long headers. It might make sense to disable this feature if you do not use a CDN.
*/
"enableSurrogateKeys": true,
/*
* Restrict the surrogate keys to results that have less than 200 items.
*/
"maxItemsForSurrogateKeys": 200
},
"logging": {
/*
* Setting the flag to true, enables well formatteds json logs.

Loading…
Cancel
Save