Browse Source

Index fixes.

pull/478/head
Sebastian 6 years ago
parent
commit
08363f4485
  1. 31
      backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs

31
backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs

@ -49,7 +49,12 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets
Index Index
.Ascending(x => x.IndexedAppId) .Ascending(x => x.IndexedAppId)
.Ascending(x => x.IsDeleted) .Ascending(x => x.IsDeleted)
.Ascending(x => x.Slug)) .Ascending(x => x.Slug)),
new CreateIndexModel<MongoAssetEntity>(
Index
.Ascending(x => x.IndexedAppId)
.Ascending(x => x.IsDeleted)
.Ascending(x => x.Id))
}, ct); }, ct);
} }
@ -93,11 +98,11 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets
{ {
using (Profiler.TraceMethod<MongoAssetRepository>("QueryAsyncByIds")) using (Profiler.TraceMethod<MongoAssetRepository>("QueryAsyncByIds"))
{ {
var find = Collection.Find(x => ids.Contains(x.Id)).Only(x => x.Id); var assetEntities =
await Collection.Find(BuildFilter(appId, ids)).Only(x => x.Id)
var assetItems = await find.ToListAsync(); .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<MongoAssetRepository>("QueryAsyncByIds")) using (Profiler.TraceMethod<MongoAssetRepository>("QueryAsyncByIds"))
{ {
var find = Collection.Find(x => ids.Contains(x.Id)).SortByDescending(x => x.LastModified); var assetEntities =
await Collection.Find(BuildFilter(appId, ids)).SortByDescending(x => x.LastModified)
var assetItems = await find.ToListAsync(); .ToListAsync();
return ResultList.Create(assetItems.Count, assetItems.OfType<IAssetEntity>()); return ResultList.Create(assetEntities.Count, assetEntities.OfType<IAssetEntity>());
} }
} }
@ -148,5 +153,13 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets
return assetEntity; return assetEntity;
} }
} }
private static FilterDefinition<MongoAssetEntity> BuildFilter(Guid appId, HashSet<Guid> ids)
{
return Filter.And(
Filter.Eq(x => x.IndexedAppId, appId),
Filter.In(x => x.Id, ids),
Filter.Ne(x => x.IsDeleted, true));
}
} }
} }

Loading…
Cancel
Save