mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.3 KiB
64 lines
2.3 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Collections.Generic;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using MongoDB.Driver;
|
|
using Squidex.Domain.Apps.Entities.Contents;
|
|
using Squidex.Infrastructure;
|
|
|
|
namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations
|
|
{
|
|
public sealed class QueryAsStream : OperationBase
|
|
{
|
|
private readonly IAppProvider appProvider;
|
|
|
|
public QueryAsStream(DataConverter converter, IAppProvider appProvider)
|
|
: base(converter)
|
|
{
|
|
this.appProvider = appProvider;
|
|
}
|
|
|
|
protected override async Task PrepareAsync(CancellationToken ct = default)
|
|
{
|
|
var indexBySchema =
|
|
new CreateIndexModel<MongoContentEntity>(Index
|
|
.Ascending(x => x.IndexedAppId)
|
|
.Ascending(x => x.IsDeleted)
|
|
.Ascending(x => x.IndexedSchemaId));
|
|
|
|
await Collection.Indexes.CreateOneAsync(indexBySchema, cancellationToken: ct);
|
|
}
|
|
|
|
public async IAsyncEnumerable<IContentEntity> StreamAll(DomainId appId, HashSet<DomainId>? schemaIds)
|
|
{
|
|
var find =
|
|
schemaIds != null ?
|
|
Collection.Find(x => x.IndexedAppId == appId && !x.IsDeleted && schemaIds.Contains(x.IndexedSchemaId)) :
|
|
Collection.Find(x => x.IndexedAppId == appId && !x.IsDeleted);
|
|
|
|
using (var cursor = await find.ToCursorAsync())
|
|
{
|
|
while (await cursor.MoveNextAsync())
|
|
{
|
|
foreach (var entity in cursor.Current)
|
|
{
|
|
var schema = await appProvider.GetSchemaAsync(appId, entity.SchemaId.Id, false);
|
|
|
|
if (schema != null)
|
|
{
|
|
entity.ParseData(schema.SchemaDef, DataConverter);
|
|
|
|
yield return entity;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|