update for database provider specific migrations

fix issues with live radar
This commit is contained in:
RaidMax
2020-11-27 21:52:52 -06:00
parent 8ef2959f63
commit 36a02b3d7b
309 changed files with 76554 additions and 1067 deletions

View File

@ -1,20 +1,24 @@
using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using IW4MAdmin.Plugins.Stats.Models;
using SharedLibraryCore.Database;
using SharedLibraryCore.Interfaces;
namespace IW4MAdmin.Application.Migration
{
public static class DatabaseHousekeeping
{
private static DateTime _cutoffDate = DateTime.UtcNow.AddMonths(-6);
private static readonly DateTime CutoffDate = DateTime.UtcNow.AddMonths(-6);
public static void RemoveOldRatings(DatabaseContext context)
public static async Task RemoveOldRatings(IDatabaseContextFactory contextFactory, CancellationToken token)
{
await using var context = contextFactory.CreateContext();
var dbSet = context.Set<EFRating>();
var itemsToDelete = dbSet.Where(rating => rating.When <= _cutoffDate);
var itemsToDelete = dbSet.Where(rating => rating.When <= CutoffDate);
dbSet.RemoveRange(itemsToDelete);
context.SaveChanges();
await context.SaveChangesAsync(token);
}
}
}