From 08363f44859e6ff1bcfb94743e3d112ea9425ba0 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 31 Jan 2020 01:21:23 +0100 Subject: [PATCH] Index fixes. --- .../Assets/MongoAssetRepository.cs | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs index efdfa97b9..30fdd1551 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs @@ -49,7 +49,12 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets Index .Ascending(x => x.IndexedAppId) .Ascending(x => x.IsDeleted) - .Ascending(x => x.Slug)) + .Ascending(x => x.Slug)), + new CreateIndexModel( + Index + .Ascending(x => x.IndexedAppId) + .Ascending(x => x.IsDeleted) + .Ascending(x => x.Id)) }, ct); } @@ -93,11 +98,11 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets { using (Profiler.TraceMethod("QueryAsyncByIds")) { - var find = Collection.Find(x => ids.Contains(x.Id)).Only(x => x.Id); - - var assetItems = await find.ToListAsync(); + var assetEntities = + await Collection.Find(BuildFilter(appId, ids)).Only(x => x.Id) + .ToListAsync(); - return assetItems.Select(x => Guid.Parse(x["_si"].AsString)).ToList(); + return assetEntities.Select(x => Guid.Parse(x["_si"].AsString)).ToList(); } } @@ -105,11 +110,11 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets { using (Profiler.TraceMethod("QueryAsyncByIds")) { - var find = Collection.Find(x => ids.Contains(x.Id)).SortByDescending(x => x.LastModified); - - var assetItems = await find.ToListAsync(); + var assetEntities = + await Collection.Find(BuildFilter(appId, ids)).SortByDescending(x => x.LastModified) + .ToListAsync(); - return ResultList.Create(assetItems.Count, assetItems.OfType()); + return ResultList.Create(assetEntities.Count, assetEntities.OfType()); } } @@ -148,5 +153,13 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets return assetEntity; } } + + private static FilterDefinition BuildFilter(Guid appId, HashSet ids) + { + return Filter.And( + Filter.Eq(x => x.IndexedAppId, appId), + Filter.In(x => x.Id, ids), + Filter.Ne(x => x.IsDeleted, true)); + } } }