// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschränkt) // All rights reserved. Licensed under the MIT license. // ========================================================================== using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using MongoDB.Driver; using NodaTime; using Squidex.Domain.Apps.Core.Contents; using Squidex.Domain.Apps.Entities.Apps; using Squidex.Domain.Apps.Entities.Contents; using Squidex.Domain.Apps.Entities.Contents.Repositories; using Squidex.Domain.Apps.Entities.Schemas; using Squidex.Hosting; using Squidex.Infrastructure; using Squidex.Infrastructure.Queries; namespace Squidex.Domain.Apps.Entities.MongoDb.Contents { public partial class MongoContentRepository : IContentRepository, IInitializable { private readonly MongoContentCollection collectionAll; private readonly MongoContentCollection collectionPublished; static MongoContentRepository() { StatusSerializer.Register(); } public MongoContentRepository(IMongoDatabase database, IAppProvider appProvider) { Guard.NotNull(appProvider, nameof(appProvider)); collectionAll = new MongoContentCollection( "States_Contents_All3", database, appProvider); collectionPublished = new MongoContentCollection( "States_Contents_Published3", database, appProvider); } public async Task InitializeAsync(CancellationToken ct = default) { await collectionAll.InitializeAsync(ct); await collectionPublished.InitializeAsync(ct); } public IAsyncEnumerable StreamAll(DomainId appId, HashSet? schemaIds) { return collectionAll.StreamAll(appId, schemaIds); } public Task> QueryAsync(IAppEntity app, List schemas, Q q, SearchScope scope) { if (scope == SearchScope.All) { return collectionAll.QueryAsync(app, schemas, q); } else { return collectionPublished.QueryAsync(app, schemas, q); } } public Task> QueryAsync(IAppEntity app, ISchemaEntity schema, Q q, SearchScope scope) { if (scope == SearchScope.All) { return collectionAll.QueryAsync(app, schema, q); } else { return collectionPublished.QueryAsync(app, schema, q); } } public Task FindContentAsync(IAppEntity app, ISchemaEntity schema, DomainId id, SearchScope scope) { if (scope == SearchScope.All) { return collectionAll.FindContentAsync(schema, id); } else { return collectionPublished.FindContentAsync(schema, id); } } public Task> QueryIdsAsync(DomainId appId, HashSet ids, SearchScope scope) { if (scope == SearchScope.All) { return collectionAll.QueryIdsAsync(appId, ids); } else { return collectionPublished.QueryIdsAsync(appId, ids); } } public Task HasReferrersAsync(DomainId appId, DomainId contentId, SearchScope scope) { if (scope == SearchScope.All) { return collectionAll.HasReferrersAsync(appId, contentId); } else { return collectionPublished.HasReferrersAsync(appId, contentId); } } public Task ResetScheduledAsync(DomainId documentId) { return collectionAll.ResetScheduledAsync(documentId); } public Task QueryScheduledWithoutDataAsync(Instant now, Func callback) { return collectionAll.QueryScheduledWithoutDataAsync(now, callback); } public Task> QueryIdsAsync(DomainId appId, DomainId schemaId, FilterNode filterNode) { return collectionAll.QueryIdsAsync(appId, schemaId, filterNode); } public IEnumerable> GetInternalCollections() { yield return collectionAll.GetInternalCollection(); yield return collectionPublished.GetInternalCollection(); } } }