Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Squidex/squidex
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Nov 14, 2024
2 parents fbd7931 + 356c80f commit ee3f022
Show file tree
Hide file tree
Showing 59 changed files with 1,880 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
uses: actions/[email protected]

- name: Prepare - Inject short Variables
uses: rlespinasse/github-slug-action@v4.5.0
uses: rlespinasse/github-slug-action@v5.0.0

- name: Prepare - Setup QEMU
uses: docker/[email protected]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
uses: actions/[email protected]

- name: Prepare - Inject short Variables
uses: rlespinasse/github-slug-action@v4.5.0
uses: rlespinasse/github-slug-action@v5.0.0

- name: Prepare - Setup QEMU
uses: docker/[email protected]
Expand Down
14 changes: 10 additions & 4 deletions backend/extensions/Squidex.Extensions/APM/Otlp/OtlpPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using OpenTelemetry.Logs;
using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;
using Squidex.Infrastructure;
using Squidex.Infrastructure.Plugins;
Expand All @@ -26,9 +28,14 @@ public Configurator(IConfiguration config)

public void Configure(TracerProviderBuilder builder)
{
// See: https://docs.microsoft.com/aspnet/core/grpc/troubleshoot#call-insecure-grpc-services-with-net-core-client
AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
builder.AddOtlpExporter(options =>
{
config.GetSection("logging:otlp").Bind(options);
});
}

public void Configure(MeterProviderBuilder builder)
{
builder.AddOtlpExporter(options =>
{
config.GetSection("logging:otlp").Bind(options);
Expand All @@ -40,8 +47,7 @@ public void ConfigureServices(IServiceCollection services, IConfiguration config
{
if (config.GetValue<bool>("logging:otlp:enabled"))
{
services.AddSingleton<ITelemetryConfigurator,
Configurator>();
services.AddSingleton<ITelemetryConfigurator, Configurator>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,15 @@ public static List<DomainId> ToIds(this JsValue? value)
{
var ids = new List<DomainId>();

if (value?.IsString() == true)
if (value is JsString s)
{
ids.Add(DomainId.Create(value.ToString()));
ids.Add(DomainId.Create(s.AsString()));
}
else if (value?.IsArray() == true)
else if (value is JsArray a)
{
foreach (var item in value.AsArray())
foreach (var item in a.OfType<JsString>())
{
if (item.IsString())
{
ids.Add(DomainId.Create(item.ToString()));
}
ids.Add(DomainId.Create(item.AsString()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,13 @@ public static JsonValue Map(JsValue? value)
return number;
}

if (value.IsArray())
if (value is JsArray a)
{
var arr = value.AsArray();
var result = new JsonArray((int)a.Length);

var result = new JsonArray((int)arr.Length);

for (var i = 0; i < arr.Length; i++)
for (var i = 0; i < a.Length; i++)
{
result.Add(Map(arr.Get(i.ToString(CultureInfo.InvariantCulture))));
result.Add(Map(a.Get(i.ToString(CultureInfo.InvariantCulture))));
}

return result;
Expand All @@ -132,10 +130,8 @@ public static JsonValue Map(JsValue? value)
return JsonValue.Create(wrapper.Target);
}

if (value.IsObject())
if (value is ObjectInstance obj)
{
var obj = value.AsObject();

var result = new JsonObject();

foreach (var (key, propertyDescriptor) in obj.GetOwnProperties())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using System.Diagnostics.CodeAnalysis;
using MongoDB.Bson;
using Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations;
using Squidex.Infrastructure.Queries;
using Squidex.Infrastructure.States;

namespace Squidex.Domain.Apps.Entities.MongoDb.Contents;

public static class IndexParser
{
public static bool TryParse(BsonDocument source, string prefix, [MaybeNullWhen(false)] out IndexDefinition index)
{
index = null!;

if (!source.TryGetValue("name", out var name) || name.BsonType != BsonType.String)
{
return false;
}

if (!name.AsString.StartsWith(prefix, StringComparison.Ordinal))
{
return false;
}

if (!source.TryGetValue("key", out var keys) || keys.BsonType != BsonType.Document)
{
return false;
}

var definition = new IndexDefinition();
foreach (var property in keys.AsBsonDocument)
{
if (property.Value.BsonType != BsonType.Int32)
{
return false;
}

var fieldName = Adapt.MapPathReverse(property.Name).ToString();

var order = property.Value.AsInt32 < 0 ?
SortOrder.Descending :
SortOrder.Ascending;

definition.Add(new IndexField(fieldName, order));
}

if (definition.Count == 0)
{
return false;
}

index = definition;
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Squidex.Domain.Apps.Core.Apps;
using Squidex.Domain.Apps.Core.Contents;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Entities.Contents;
using Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations;
using Squidex.Infrastructure;
using Squidex.Infrastructure.MongoDb;
Expand Down Expand Up @@ -318,4 +319,33 @@ public async Task AddCollectionsAsync(MongoContentEntity entity, Action<IMongoCo

add(Collection, entity);
}

public async Task CreateIndexAsync(DomainId appId, DomainId schemaId, IndexDefinition index,
CancellationToken ct = default)
{
if (queryInDedicatedCollection != null)
{
await queryInDedicatedCollection.CreateIndexAsync(appId, schemaId, index, ct);
}
}

public async Task DropIndexAsync(DomainId appId, DomainId schemaId, string name,
CancellationToken ct = default)
{
if (queryInDedicatedCollection != null)
{
await queryInDedicatedCollection.DropIndexAsync(appId, schemaId, name, ct);
}
}

public async Task<List<IndexDefinition>> GetIndexesAsync(DomainId appId, DomainId schemaId,
CancellationToken ct = default)
{
if (queryInDedicatedCollection != null)
{
return await queryInDedicatedCollection.GetIndexesAsync(appId, schemaId, ct);
}

return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using Squidex.Infrastructure.Json.Objects;
using Squidex.Infrastructure.MongoDb;
using Squidex.Infrastructure.Queries;
using Squidex.Infrastructure.States;

namespace Squidex.Domain.Apps.Entities.MongoDb.Contents;

Expand Down Expand Up @@ -130,6 +131,24 @@ public Task ResetScheduledAsync(DomainId appId, DomainId contentId, SearchScope
return GetCollection(SearchScope.All).ResetScheduledAsync(appId, contentId, ct);
}

public Task CreateIndexAsync(DomainId appId, DomainId schemaId, IndexDefinition index,
CancellationToken ct = default)
{
return GetCollection(SearchScope.All).CreateIndexAsync(appId, schemaId, index, ct);
}

public Task<List<IndexDefinition>> GetIndexesAsync(DomainId appId, DomainId schemaId,
CancellationToken ct = default)
{
return GetCollection(SearchScope.All).GetIndexesAsync(appId, schemaId, ct);
}

public Task DropIndexAsync(DomainId appId, DomainId schemaId, string name,
CancellationToken ct = default)
{
return GetCollection(SearchScope.All).DropIndexAsync(appId, schemaId, name, ct);
}

private MongoContentCollection GetCollection(SearchScope scope)
{
return scope == SearchScope.All ? collectionComplete : collectionPublished;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// ==========================================================================

using System.Runtime.CompilerServices;
using System.Xml.Linq;
using NodaTime;
using Squidex.Domain.Apps.Core.Apps;
using Squidex.Domain.Apps.Core.Contents;
Expand Down Expand Up @@ -79,6 +80,24 @@ public IAsyncEnumerable<Content> StreamReferencing(DomainId appId, DomainId refe
return Shard(appId).StreamReferencing(appId, references, take, scope, ct);
}

public Task CreateIndexAsync(DomainId appId, DomainId schemaId, IndexDefinition index,
CancellationToken ct = default)
{
return Shard(appId).CreateIndexAsync(appId, schemaId, index, ct);
}

public Task DropIndexAsync(DomainId appId, DomainId schemaId, string name,
CancellationToken ct = default)
{
return Shard(appId).DropIndexAsync(appId, schemaId, name, ct);
}

public Task<List<IndexDefinition>> GetIndexesAsync(DomainId appId, DomainId schemaId,
CancellationToken ct = default)
{
return Shard(appId).GetIndexesAsync(appId, schemaId, ct);
}

public async IAsyncEnumerable<Content> StreamScheduledWithoutDataAsync(Instant now, SearchScope scope,
[EnumeratorCancellation] CancellationToken ct = default)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using GraphQL;
using MongoDB.Bson.Serialization;
using Squidex.Infrastructure;
using Squidex.Infrastructure.MongoDb;
Expand All @@ -16,7 +17,9 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations;
public static class Adapt
{
private static Dictionary<string, PropertyPath> pathMap;
private static Dictionary<string, PropertyPath> pathReverseMap;
private static Dictionary<string, string> propertyMap;
private static Dictionary<string, string> propertyReverseMap;

public static IReadOnlyDictionary<string, string> PropertyMap
{
Expand All @@ -28,13 +31,29 @@ public static IReadOnlyDictionary<string, string> PropertyMap
StringComparer.OrdinalIgnoreCase);
}

public static IReadOnlyDictionary<string, string> PropertyReverseMap
{
get => propertyReverseMap ??=
BsonClassMap.LookupClassMap(typeof(MongoContentEntity)).AllMemberMaps
.ToDictionary(
x => x.ElementName,
x => x.MemberName.ToCamelCase(),
StringComparer.OrdinalIgnoreCase);
}

public static IReadOnlyDictionary<string, PropertyPath> PathMap
{
get => pathMap ??= PropertyMap.ToDictionary(x => x.Key, x => (PropertyPath)x.Value);
}

public static IReadOnlyDictionary<string, PropertyPath> PathReverseMap
{
get => pathReverseMap ??= PropertyReverseMap.ToDictionary(x => x.Key, x => (PropertyPath)x.Value);
}

public static PropertyPath MapPath(PropertyPath path)
{
// Shortcut to prevent allocations for most used field names.
if (path.Count == 1 && PathMap.TryGetValue(path[0], out var mappedPath))
{
return mappedPath;
Expand All @@ -52,12 +71,40 @@ public static PropertyPath MapPath(PropertyPath path)

for (var i = 1; i < path.Count; i++)
{
// MongoDB does not accept all field names.
result[i] = result[i].UnescapeEdmField().JsonToBsonName().JsonEscape();
}

return result;
}

public static PropertyPath MapPathReverse(PropertyPath path)
{
// Shortcut to prevent allocations for most used field names.
if (path.Count == 1 && PathReverseMap.TryGetValue(path[0], out var mappedPath))
{
return mappedPath;
}

var result = new List<string>(path);

if (result.Count > 0)
{
if (PropertyReverseMap.TryGetValue(path[0], out var mapped))
{
result[0] = mapped;
}
}

for (var i = 1; i < path.Count; i++)
{
// MongoDB does not accept all field names.
result[i] = result[i].EscapeEdmField().BsonToJsonName().JsonUnescape().ToCamelCase();
}

return result;
}

public static ClrQuery AdjustToModel(this ClrQuery query, DomainId appId)
{
if (query.Filter != null)
Expand Down
Loading

0 comments on commit ee3f022

Please sign in to comment.