// ========================================================================== // 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.Entities.Apps; using Squidex.Domain.Apps.Entities.Contents; using Squidex.Domain.Apps.Entities.Contents.Repositories; using Squidex.Domain.Apps.Entities.Contents.Text; using Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations; using Squidex.Domain.Apps.Entities.Schemas; using Squidex.Infrastructure; using Squidex.Infrastructure.Json; using Squidex.Infrastructure.Queries; namespace Squidex.Domain.Apps.Entities.MongoDb.Contents { public partial class MongoContentRepository : IContentRepository, IInitializable { private readonly IAppProvider appProvider; private readonly DataConverter converter; private readonly MongoContentCollectionAll collectionAll; private readonly MongoContentCollectionPublished collectionPublished; static MongoContentRepository() { StatusSerializer.Register(); } public MongoContentRepository(IMongoDatabase database, IAppProvider appProvider, ITextIndex indexer, IJsonSerializer serializer) { Guard.NotNull(appProvider, nameof(appProvider)); Guard.NotNull(serializer, nameof(serializer)); this.appProvider = appProvider; converter = new DataConverter(serializer); collectionAll = new MongoContentCollectionAll(database, appProvider, indexer, converter); collectionPublished = new MongoContentCollectionPublished(database, appProvider, indexer, converter); } public async Task InitializeAsync(CancellationToken ct = default) { await collectionAll.InitializeAsync(ct); await collectionPublished.InitializeAsync(ct); } public Task> QueryAsync(IAppEntity app, ISchemaEntity schema, ClrQuery query, SearchScope scope) { if (scope == SearchScope.All) { return collectionAll.QueryAsync(app, schema, query); } else { return collectionPublished.QueryAsync(app, schema, query); } } public Task> QueryAsync(IAppEntity app, ISchemaEntity schema, HashSet ids, SearchScope scope) { if (scope == SearchScope.All) { return collectionAll.QueryAsync(app, schema, ids); } else { return collectionPublished.QueryAsync(app, schema, ids); } } public Task> QueryAsync(IAppEntity app, HashSet ids, SearchScope scope) { if (scope == SearchScope.All) { return collectionAll.QueryAsync(app, ids); } else { return collectionPublished.QueryAsync(app, ids); } } public Task FindContentAsync(IAppEntity app, ISchemaEntity schema, Guid id, SearchScope scope) { if (scope == SearchScope.All) { return collectionAll.FindContentAsync(schema, id); } else { return collectionPublished.FindContentAsync(schema, id); } } public Task> QueryIdsAsync(Guid appId, HashSet ids, SearchScope scope) { if (scope == SearchScope.All) { return collectionAll.QueryIdsAsync(appId, ids); } else { return collectionPublished.QueryIdsAsync(appId, ids); } } public Task ResetScheduledAsync(Guid id) { return collectionAll.ResetScheduledAsync(id); } public Task QueryScheduledWithoutDataAsync(Instant now, Func callback) { return collectionAll.QueryScheduledWithoutDataAsync(now, callback); } public Task> QueryIdsAsync(Guid appId, Guid schemaId, FilterNode filterNode) { return collectionAll.QueryIdsAsync(appId, schemaId, filterNode); } public Task HasReferrersAsync(Guid contentId) { return collectionAll.HasReferrersAsync(contentId); } public IEnumerable> GetInternalCollections() { yield return collectionAll.GetInternalCollection(); yield return collectionPublished.GetInternalCollection(); } } }