Optimize mongodb deletion for feature values

pull/14514/head
Enis Necipoglu 2 years ago
parent 621cbd1d64
commit 5973d54e9b

@ -57,9 +57,10 @@ public class MongoFeatureValueRepository :
string providerKey, string providerKey,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var entities = await (await GetMongoQueryableAsync(cancellationToken)) var dbContext = await GetDbContextAsync();
.Where(s => s.ProviderName == providerName && s.ProviderKey == providerKey)
.ToListAsync(GetCancellationToken(cancellationToken)); await dbContext.FeatureValues
await DeleteManyAsync(entities, true, GetCancellationToken(cancellationToken)); .DeleteManyAsync(x => x.ProviderName == providerName && x.ProviderKey == providerKey, GetCancellationToken(cancellationToken));
} }
} }

@ -1,7 +1,10 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Shouldly; using Shouldly;
using Volo.Abp.Features; using Volo.Abp.Features;
using Volo.Abp.Modularity; using Volo.Abp.Modularity;
using Volo.Abp.Uow;
using Xunit; using Xunit;
namespace Volo.Abp.FeatureManagement; namespace Volo.Abp.FeatureManagement;
@ -79,6 +82,24 @@ public abstract class FeatureValueRepository_Tests<TStartupModule> : FeatureMana
var exception = await Record.ExceptionAsync(async () => var exception = await Record.ExceptionAsync(async () =>
await Repository.DeleteAsync(TestFeatureDefinitionProvider.SocialLogins, "true")); await Repository.DeleteAsync(TestFeatureDefinitionProvider.SocialLogins, "true"));
Assert.Null(exception); Assert.Null(exception);
} }
[Fact]
public async Task DeleteForProviderNameAndKey()
{
using (var scope = ServiceProvider.CreateScope())
{
var uowManager = scope.ServiceProvider.GetRequiredService<IUnitOfWorkManager>();
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();
}
} }

Loading…
Cancel
Save