mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-03 02:28:39 +00:00
Add CleanupUnusedLocationsMaintenanceJob
This commit is contained in:
parent
f680c90d47
commit
34bd2ec111
1 changed files with 24 additions and 0 deletions
|
@ -0,0 +1,24 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace LBPUnion.ProjectLighthouse.Maintenance.MaintenanceJobs
|
||||||
|
{
|
||||||
|
public class CleanupUnusedLocationsMaintenanceJob : IMaintenanceJob
|
||||||
|
{
|
||||||
|
private readonly Database database = new();
|
||||||
|
public string Name() => "Cleanup Unused Locations";
|
||||||
|
public string Description() => "Cleanup unused locations in the database.";
|
||||||
|
|
||||||
|
public 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue