1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 00:22:50 -05:00
Files
bitwarden/src/Infrastructure.EntityFramework/Repositories/MaintenanceRepository.cs
Justin Baur 1e0182008b [PM-2943] Enable Nullable Repositories in Unowned Files (#4549)
* Enable Nullable In Unowned Repos

* Update More Tests

* Move to One If

* Fix Collections

* Format

* Add Migrations

* Move Pragma Annotation

* Add Better Assert Message
2024-07-24 09:48:09 -04:00

56 lines
1.6 KiB
C#

using AutoMapper;
using Bit.Core.Repositories;
using Microsoft.Extensions.DependencyInjection;
#nullable enable
namespace Bit.Infrastructure.EntityFramework.Repositories;
public class MaintenanceRepository : BaseEntityFrameworkRepository, IMaintenanceRepository
{
public MaintenanceRepository(IServiceScopeFactory serviceScopeFactory, IMapper mapper)
: base(serviceScopeFactory, mapper)
{ }
public async Task DeleteExpiredGrantsAsync()
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var query = from g in dbContext.Grants
where g.ExpirationDate < DateTime.UtcNow
select g;
dbContext.RemoveRange(query);
await dbContext.SaveChangesAsync();
}
}
public async Task DeleteExpiredSponsorshipsAsync(DateTime validUntilBeforeDate)
{
using (var scope = ServiceScopeFactory.CreateScope())
{
var dbContext = GetDatabaseContext(scope);
var query = from s in dbContext.OrganizationSponsorships
where s.ValidUntil < validUntilBeforeDate
select s;
dbContext.RemoveRange(query);
await dbContext.SaveChangesAsync();
}
}
public Task DisableCipherAutoStatsAsync()
{
return Task.CompletedTask;
}
public Task RebuildIndexesAsync()
{
return Task.CompletedTask;
}
public Task UpdateStatisticsAsync()
{
return Task.CompletedTask;
}
}