From 5973d54e9b573e41391dfcd9b433b454dcba692f Mon Sep 17 00:00:00 2001 From: Enis Necipoglu Date: Thu, 3 Nov 2022 10:45:21 +0300 Subject: [PATCH] Optimize mongodb deletion for feature values --- .../MongoDB/MongoFeatureValueRepository.cs | 9 ++++---- .../FeatureValueRepository_Tests.cs | 23 ++++++++++++++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureValueRepository.cs b/modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureValueRepository.cs index 235ef191ce..4d4fbedcfd 100644 --- a/modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureValueRepository.cs +++ b/modules/feature-management/src/Volo.Abp.FeatureManagement.MongoDB/Volo/Abp/FeatureManagement/MongoDB/MongoFeatureValueRepository.cs @@ -57,9 +57,10 @@ public class MongoFeatureValueRepository : string providerKey, CancellationToken cancellationToken = default) { - var entities = await (await GetMongoQueryableAsync(cancellationToken)) - .Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey) - .ToListAsync(GetCancellationToken(cancellationToken)); - await DeleteManyAsync(entities, true, GetCancellationToken(cancellationToken)); + var dbContext = await GetDbContextAsync(); + + await dbContext.FeatureValues + .DeleteManyAsync(x => x.ProviderName == providerName && x.ProviderKey == providerKey, GetCancellationToken(cancellationToken)); + } } diff --git a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureValueRepository_Tests.cs b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureValueRepository_Tests.cs index 003073991b..b739cdf7e7 100644 --- a/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureValueRepository_Tests.cs +++ b/modules/feature-management/test/Volo.Abp.FeatureManagement.TestBase/Volo/Abp/FeatureManagement/FeatureValueRepository_Tests.cs @@ -1,7 +1,10 @@ using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using Shouldly; using Volo.Abp.Features; using Volo.Abp.Modularity; +using Volo.Abp.Uow; using Xunit; namespace Volo.Abp.FeatureManagement; @@ -79,6 +82,24 @@ public abstract class FeatureValueRepository_Tests : FeatureMana var exception = await Record.ExceptionAsync(async () => await Repository.DeleteAsync(TestFeatureDefinitionProvider.SocialLogins, "true")); Assert.Null(exception); - } + + [Fact] + public async Task DeleteForProviderNameAndKey() + { + using (var scope = ServiceProvider.CreateScope()) + { + var uowManager = scope.ServiceProvider.GetRequiredService(); + + using (var uow = uowManager.Begin(new AbpUnitOfWorkOptions())) + { + await Repository.DeleteAsync(TestFeatureDefinitionProvider.SocialLogins, "true"); + + await uow.CompleteAsync(); + } + } + + var features = await Repository.GetListAsync(TestFeatureDefinitionProvider.SocialLogins, "true"); + features.ShouldBeEmpty(); + } }