Browse Source

Performance improvements.

pull/403/head
Sebastian Stehle 7 years ago
parent
commit
fa1d23d531
  1. 2
      src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj
  2. 28
      src/Squidex.Domain.Apps.Entities/Context.cs
  3. 2
      src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj
  4. 4
      src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj
  5. 1
      src/Squidex.Infrastructure/Queries/Json/ValueConverter.cs
  6. 25
      src/Squidex.Infrastructure/Security/Permission.Part.cs
  7. 21
      src/Squidex.Infrastructure/Security/Permission.cs
  8. 2
      src/Squidex.Infrastructure/Squidex.Infrastructure.csproj
  9. 2
      src/Squidex.Web/ContextExtensions.cs
  10. 3
      src/Squidex.Web/ContextProvider.cs
  11. 7
      src/Squidex.Web/Pipeline/AppResolver.cs
  12. 4
      src/Squidex/Squidex.csproj
  13. 3
      tests/Squidex.Domain.Apps.Entities.Tests/Apps/AppCommandMiddlewareTests.cs
  14. 3
      tests/Squidex.Domain.Apps.Entities.Tests/Contents/ContentCommandMiddlewareTests.cs
  15. 2
      tests/Squidex.Domain.Apps.Entities.Tests/Squidex.Domain.Apps.Entities.Tests.csproj
  16. 2
      tests/Squidex.Web.Tests/ApiPermissionAttributeTests.cs
  17. 3
      tests/Squidex.Web.Tests/CommandMiddlewares/EnrichWithAppIdCommandMiddlewareTests.cs
  18. 12
      tools/LoadTest/ClientQueryFixture.cs
  19. 7
      tools/LoadTest/QueryBenchmarks.cs
  20. 2
      tools/Migrate_00/Migrate_00.csproj

2
src/Squidex.Domain.Apps.Entities.MongoDb/Squidex.Domain.Apps.Entities.MongoDb.csproj

@ -17,7 +17,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.OData.Core" Version="7.6.0" />
<PackageReference Include="MongoDB.Driver" Version="2.9.0" />
<PackageReference Include="MongoDB.Driver" Version="2.9.1" />
<PackageReference Include="RefactoringEssentials" Version="5.6.0" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />

28
src/Squidex.Domain.Apps.Entities/Context.cs

@ -9,6 +9,7 @@ using System;
using System.Collections.Generic;
using System.Security.Claims;
using Squidex.Domain.Apps.Entities.Apps;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Security;
using Squidex.Shared;
using Squidex.Shared.Identity;
@ -21,27 +22,32 @@ namespace Squidex.Domain.Apps.Entities
public IAppEntity App { get; set; }
public ClaimsPrincipal User { get; set; }
public ClaimsPrincipal User { get; }
public PermissionSet Permissions
{
get { return User?.Permissions() ?? PermissionSet.Empty; }
}
public PermissionSet Permissions { get; private set; } = PermissionSet.Empty;
public bool IsFrontendClient { get; private set; }
public bool IsFrontendClient
public Context(ClaimsPrincipal user)
{
get { return User != null && User.IsInClient(DefaultClients.Frontend); }
Guard.NotNull(user, nameof(user));
User = user;
UpdatePermissions();
}
public Context()
public Context(ClaimsPrincipal user, IAppEntity app)
: this(user)
{
App = app;
}
public Context(ClaimsPrincipal user, IAppEntity app)
public void UpdatePermissions()
{
User = user;
Permissions = User.Permissions();
App = app;
IsFrontendClient = User.IsInClient(DefaultClients.Frontend);
}
public Context Clone()

2
src/Squidex.Domain.Users.MongoDb/Squidex.Domain.Users.MongoDb.csproj

@ -17,7 +17,7 @@
<PackageReference Include="IdentityServer4" Version="2.5.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.Win32.Registry" Version="4.5.0" />
<PackageReference Include="MongoDB.Driver" Version="2.9.0" />
<PackageReference Include="MongoDB.Driver" Version="2.9.1" />
<PackageReference Include="RefactoringEssentials" Version="5.6.0" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
<PackageReference Include="System.Security.Principal.Windows" Version="4.5.1" />

4
src/Squidex.Infrastructure.MongoDb/Squidex.Infrastructure.MongoDb.csproj

@ -12,8 +12,8 @@
<ProjectReference Include="..\Squidex.Infrastructure\Squidex.Infrastructure.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.9.0" />
<PackageReference Include="MongoDB.Driver.GridFS" Version="2.9.0" />
<PackageReference Include="MongoDB.Driver" Version="2.9.1" />
<PackageReference Include="MongoDB.Driver.GridFS" Version="2.9.1" />
<PackageReference Include="RefactoringEssentials" Version="5.6.0" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="4.9.0" />

1
src/Squidex.Infrastructure/Queries/Json/ValueConverter.cs

@ -7,7 +7,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using NJsonSchema;
using NodaTime;
using NodaTime.Text;

25
src/Squidex.Infrastructure/Security/Permission.Part.cs

@ -6,7 +6,6 @@
// ==========================================================================
using System;
using System.Collections.Generic;
using System.Linq;
namespace Squidex.Infrastructure.Security
@ -18,11 +17,11 @@ namespace Squidex.Infrastructure.Security
private static readonly char[] AlternativeSeparators = { '|' };
private static readonly char[] MainSeparators = { '.' };
public readonly HashSet<string> Alternatives;
public readonly string[] Alternatives;
public readonly bool Exclusion;
public Part(HashSet<string> alternatives, bool exclusion)
public Part(string[] alternatives, bool exclusion)
{
Alternatives = alternatives;
@ -31,10 +30,16 @@ namespace Squidex.Infrastructure.Security
public static Part[] ParsePath(string path)
{
return path
.Split(MainSeparators, StringSplitOptions.RemoveEmptyEntries)
.Select(Parse)
.ToArray();
var parts = path.Split(MainSeparators, StringSplitOptions.RemoveEmptyEntries);
var result = new Part[parts.Length];
for (var i = 0; i < result.Length; i++)
{
result[i] = Parse(parts[i]);
}
return result;
}
public static Part Parse(string part)
@ -48,13 +53,11 @@ namespace Squidex.Infrastructure.Security
part = part.Substring(1);
}
HashSet<string> alternatives = null;
string[] alternatives = null;
if (part != Any)
{
alternatives =
part.Split(AlternativeSeparators, StringSplitOptions.RemoveEmptyEntries)
.ToHashSet(StringComparer.OrdinalIgnoreCase);
alternatives = part.Split(AlternativeSeparators, StringSplitOptions.RemoveEmptyEntries);
}
return new Part(alternatives, isExclusion);

21
src/Squidex.Infrastructure/Security/Permission.cs

@ -15,20 +15,31 @@ namespace Squidex.Infrastructure.Security
public const string Exclude = "^";
private readonly string id;
private readonly Lazy<Part[]> idParts;
private Part[] path;
public string Id
{
get { return id; }
}
private Part[] Path
{
get
{
if (path == null)
{
path = Part.ParsePath(id);
}
return path;
}
}
public Permission(string id)
{
Guard.NotNullOrEmpty(id, nameof(id));
this.id = id;
idParts = new Lazy<Part[]>(() => Part.ParsePath(id));
}
public bool Allows(Permission permission)
@ -38,7 +49,7 @@ namespace Squidex.Infrastructure.Security
return false;
}
return Covers(idParts.Value, permission.idParts.Value);
return Covers(Path, permission.Path);
}
public bool Includes(Permission permission)
@ -48,7 +59,7 @@ namespace Squidex.Infrastructure.Security
return false;
}
return PartialCovers(idParts.Value, permission.idParts.Value);
return PartialCovers(Path, permission.Path);
}
private static bool Covers(Part[] given, Part[] requested)

2
src/Squidex.Infrastructure/Squidex.Infrastructure.csproj

@ -8,7 +8,7 @@
<DebugSymbols>True</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentFTP" Version="27.0.2" />
<PackageReference Include="FluentFTP" Version="27.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" Version="2.2.0" />

2
src/Squidex.Web/ContextExtensions.cs

@ -19,7 +19,7 @@ namespace Squidex.Web
if (context == null)
{
context = new Context { User = httpContext.User };
context = new Context(httpContext.User);
foreach (var header in httpContext.Request.Headers)
{

3
src/Squidex.Web/ContextProvider.cs

@ -5,6 +5,7 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.Security.Claims;
using System.Threading;
using Microsoft.AspNetCore.Http;
using Squidex.Domain.Apps.Entities;
@ -25,7 +26,7 @@ namespace Squidex.Web
{
if (asyncLocal.Value == null)
{
asyncLocal.Value = new Context();
asyncLocal.Value = new Context(new ClaimsPrincipal(new ClaimsIdentity()));
}
return asyncLocal.Value;

7
src/Squidex.Web/Pipeline/AppResolver.cs

@ -66,11 +66,12 @@ namespace Squidex.Web.Pipeline
}
}
var permissionSet = user.Permissions();
var appContext = context.HttpContext.Context();
context.HttpContext.Context().App = app;
appContext.App = app;
appContext.UpdatePermissions();
if (!permissionSet.Includes(Permissions.ForApp(Permissions.App, appName)) && !AllowAnonymous(context))
if (!appContext.Permissions.Includes(Permissions.ForApp(Permissions.App, appName)) && !AllowAnonymous(context))
{
context.Result = new NotFoundResult();
return;

4
src/Squidex/Squidex.csproj

@ -66,14 +66,14 @@
<PackageReference Include="Microsoft.Orleans.Core" Version="2.4.1" />
<PackageReference Include="Microsoft.Orleans.Core.Abstractions" Version="2.4.1" />
<PackageReference Include="Microsoft.Orleans.OrleansRuntime" Version="2.4.1" />
<PackageReference Include="MongoDB.Driver" Version="2.9.0" />
<PackageReference Include="MongoDB.Driver" Version="2.9.1" />
<PackageReference Include="Namotion.Reflection" Version="1.0.6" />
<PackageReference Include="NJsonSchema" Version="10.0.22" />
<PackageReference Include="NSwag.AspNetCore" Version="13.0.5" />
<PackageReference Include="OpenCover" Version="4.7.922" PrivateAssets="all" />
<PackageReference Include="Orleans.Providers.MongoDB" Version="2.7.0" />
<PackageReference Include="Orleans.WebHostCompatibilityLayer" Version="2.3.1" />
<PackageReference Include="OrleansDashboard" Version="2.4.3" />
<PackageReference Include="OrleansDashboard" Version="2.4.4" />
<PackageReference Include="RefactoringEssentials" Version="5.6.0" PrivateAssets="all" />
<PackageReference Include="ReportGenerator" Version="4.2.15" PrivateAssets="all" />
<PackageReference Include="Squidex.ClientLibrary" Version="3.9.0" />

3
tests/Squidex.Domain.Apps.Entities.Tests/Apps/AppCommandMiddlewareTests.cs

@ -6,6 +6,7 @@
// ==========================================================================
using System;
using System.Security.Claims;
using System.Threading.Tasks;
using FakeItEasy;
using Orleans;
@ -20,7 +21,7 @@ namespace Squidex.Domain.Apps.Entities.Apps
{
private readonly IContextProvider contextProvider = A.Fake<IContextProvider>();
private readonly Guid appId = Guid.NewGuid();
private readonly Context requestContext = new Context();
private readonly Context requestContext = new Context(new ClaimsPrincipal());
private readonly AppCommandMiddleware sut;
public sealed class MyCommand : SquidexCommand

3
tests/Squidex.Domain.Apps.Entities.Tests/Contents/ContentCommandMiddlewareTests.cs

@ -6,6 +6,7 @@
// ==========================================================================
using System;
using System.Security.Claims;
using System.Threading.Tasks;
using FakeItEasy;
using Orleans;
@ -21,7 +22,7 @@ namespace Squidex.Domain.Apps.Entities.Contents
private readonly IContentEnricher contentEnricher = A.Fake<IContentEnricher>();
private readonly IContextProvider contextProvider = A.Fake<IContextProvider>();
private readonly Guid contentId = Guid.NewGuid();
private readonly Context requestContext = new Context();
private readonly Context requestContext = new Context(new ClaimsPrincipal());
private readonly ContentCommandMiddleware sut;
public sealed class MyCommand : SquidexCommand

2
tests/Squidex.Domain.Apps.Entities.Tests/Squidex.Domain.Apps.Entities.Tests.csproj

@ -21,7 +21,7 @@
<PackageReference Include="FluentAssertions" Version="5.8.0" />
<PackageReference Include="GraphQL" Version="2.4.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
<PackageReference Include="MongoDB.Driver" Version="2.9.0" />
<PackageReference Include="MongoDB.Driver" Version="2.9.1" />
<PackageReference Include="RefactoringEssentials" Version="5.6.0" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
<PackageReference Include="System.ValueTuple" Version="4.5.0" />

2
tests/Squidex.Web.Tests/ApiPermissionAttributeTests.cs

@ -38,7 +38,7 @@ namespace Squidex.Web
actionExecutingContext = new ActionExecutingContext(actionContext, new List<IFilterMetadata>(), new Dictionary<string, object>(), this);
actionExecutingContext.HttpContext = httpContext;
actionExecutingContext.HttpContext.Context().User = new ClaimsPrincipal(user);
actionExecutingContext.HttpContext.User = new ClaimsPrincipal(user);
next = () =>
{

3
tests/Squidex.Web.Tests/CommandMiddlewares/EnrichWithAppIdCommandMiddlewareTests.cs

@ -6,6 +6,7 @@
// ==========================================================================
using System;
using System.Security.Claims;
using System.Threading.Tasks;
using FakeItEasy;
using Squidex.Domain.Apps.Entities;
@ -23,7 +24,7 @@ namespace Squidex.Web.CommandMiddlewares
private readonly IContextProvider contextProvider = A.Fake<IContextProvider>();
private readonly ICommandBus commandBus = A.Fake<ICommandBus>();
private readonly NamedId<Guid> appId = NamedId.Of(Guid.NewGuid(), "my-app");
private readonly Context appContext = new Context();
private readonly Context appContext = new Context(new ClaimsPrincipal());
private readonly EnrichWithAppIdCommandMiddleware sut;
public EnrichWithAppIdCommandMiddlewareTests()

12
tools/LoadTest/ClientQueryFixture.cs

@ -36,13 +36,13 @@ namespace LoadTest
{
Name = TestClient.TestSchemaName,
Fields = new List<UpsertSchemaFieldDto>
{
new UpsertSchemaFieldDto
{
Name = TestClient.TestSchemaName,
Properties = new NumberFieldPropertiesDto()
}
},
new UpsertSchemaFieldDto
{
Name = TestClient.TestSchemaField,
Properties = new NumberFieldPropertiesDto()
}
},
IsPublished = true
});
}

7
tools/LoadTest/QueryBenchmarks.cs

@ -133,14 +133,13 @@ namespace LoadTest
var avg = elapsedMs.Average();
Assert.Equal(0, errors);
Assert.Equal(count, numUsers * numIterationsPerUser);
Assert.InRange(max, 0, expectedAvg * 10);
Assert.InRange(min, 0, expectedAvg);
Assert.InRange(avg, 0, expectedAvg);
Assert.Equal(0, errors);
Assert.Equal(count, numUsers * numIterationsPerUser);
}
}
}

2
tools/Migrate_00/Migrate_00.csproj

@ -6,7 +6,7 @@
<LangVersion>7.3</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.9.0" />
<PackageReference Include="MongoDB.Driver" Version="2.9.1" />
<PackageReference Include="RefactoringEssentials" Version="5.6.0" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
</ItemGroup>

Loading…
Cancel
Save