mirror of https://github.com/Squidex/squidex.git
Browse Source
* Check references when deleting. * Tests fixed * Performance optimizations.pull/585/head
committed by
GitHub
97 changed files with 788 additions and 252 deletions
@ -0,0 +1,32 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using MongoDB.Bson.Serialization; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.MongoDb.Assets |
|||
{ |
|||
internal static class Fields |
|||
{ |
|||
private static readonly Lazy<string> AssetIdField = new Lazy<string>(GetAssetIdField); |
|||
private static readonly Lazy<string> AssetFolderIdField = new Lazy<string>(GetAssetFolderIdField); |
|||
|
|||
public static string AssetId => AssetIdField.Value; |
|||
|
|||
public static string AssetFolderId => AssetFolderIdField.Value; |
|||
|
|||
private static string GetAssetIdField() |
|||
{ |
|||
return BsonClassMap.LookupClassMap(typeof(MongoAssetEntity)).GetMemberMap(nameof(MongoAssetEntity.Id)).ElementName; |
|||
} |
|||
|
|||
private static string GetAssetFolderIdField() |
|||
{ |
|||
return BsonClassMap.LookupClassMap(typeof(MongoAssetFolderEntity)).GetMemberMap(nameof(MongoAssetFolderEntity.Id)).ElementName; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using MongoDB.Bson.Serialization; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.MongoDb.Contents |
|||
{ |
|||
internal static class Fields |
|||
{ |
|||
private static readonly Lazy<string> IdField = new Lazy<string>(GetIdField); |
|||
private static readonly Lazy<string> SchemaIdField = new Lazy<string>(GetSchemaIdField); |
|||
|
|||
public static string Id => IdField.Value; |
|||
|
|||
public static string SchemaId => SchemaIdField.Value; |
|||
|
|||
private static string GetIdField() |
|||
{ |
|||
return BsonClassMap.LookupClassMap(typeof(MongoContentEntity)).GetMemberMap(nameof(MongoContentEntity.Id)).ElementName; |
|||
} |
|||
|
|||
private static string GetSchemaIdField() |
|||
{ |
|||
return BsonClassMap.LookupClassMap(typeof(MongoContentEntity)).GetMemberMap(nameof(MongoContentEntity.IndexedSchemaId)).ElementName; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading; |
|||
using System.Threading.Tasks; |
|||
using MongoDB.Driver; |
|||
using Squidex.Infrastructure.MongoDb; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations |
|||
{ |
|||
internal sealed class QueryReferrersAsync : OperationBase |
|||
{ |
|||
protected override Task PrepareAsync(CancellationToken ct = default) |
|||
{ |
|||
var index = |
|||
new CreateIndexModel<MongoContentEntity>(Index |
|||
.Ascending(x => x.ReferencedIds) |
|||
.Ascending(x => x.IsDeleted)); |
|||
|
|||
return Collection.Indexes.CreateOneAsync(index, cancellationToken: ct); |
|||
} |
|||
|
|||
public async Task<bool> DoAsync(Guid id) |
|||
{ |
|||
var filter = |
|||
Filter.And( |
|||
Filter.AnyEq(x => x.ReferencedIds, id), |
|||
Filter.Ne(x => x.IsDeleted, true), |
|||
Filter.Ne(x => x.Id, id)); |
|||
|
|||
var hasReferrerAsync = |
|||
await Collection.Find(filter).Only(x => x.Id) |
|||
.AnyAsync(); |
|||
|
|||
return hasReferrerAsync; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue