mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-01 09:48:37 +00:00
Log removed locations
This commit is contained in:
parent
34bd2ec111
commit
be01f95ac8
1 changed files with 12 additions and 3 deletions
|
@ -1,6 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LBPUnion.ProjectLighthouse.Types.Profiles;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs
|
||||
{
|
||||
|
@ -10,15 +12,22 @@ namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs
|
|||
public string Name() => "Cleanup Unused Locations";
|
||||
public string Description() => "Cleanup unused locations in the database.";
|
||||
|
||||
public Task Run()
|
||||
public async Task Run()
|
||||
{
|
||||
List<int> usedLocationIds = new();
|
||||
|
||||
usedLocationIds.AddRange(this.database.Slots.Select(slot => slot.LocationId));
|
||||
usedLocationIds.AddRange(this.database.Users.Select(user => user.LocationId));
|
||||
|
||||
this.database.RemoveRange(this.database.Locations.Where(l => !usedLocationIds.Contains(l.Id)));
|
||||
return Task.CompletedTask;
|
||||
IQueryable<Location> locationsToRemove = this.database.Locations.Where(l => !usedLocationIds.Contains(l.Id));
|
||||
|
||||
foreach (Location location in locationsToRemove)
|
||||
{
|
||||
Console.WriteLine("Removing location" + location.Id);
|
||||
this.database.Locations.Remove(location);
|
||||
}
|
||||
|
||||
await this.database.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue