forked from ddrilling/AsbCloudServer
ReportService.DeleteAllOldReportsAsync(..) optimize EF queries
This commit is contained in:
parent
3451d7ca98
commit
c34d6d39f5
@ -28,7 +28,7 @@ namespace AsbCloudInfrastructure.Background
|
|||||||
protected override async Task Action(string id, IServiceProvider services, Action<string, double?> onProgressCallback, CancellationToken token)
|
protected override async Task Action(string id, IServiceProvider services, Action<string, double?> onProgressCallback, CancellationToken token)
|
||||||
{
|
{
|
||||||
var reportService = services.GetRequiredService<IReportService>();
|
var reportService = services.GetRequiredService<IReportService>();
|
||||||
await reportService.DeleteAllOldReportsAsync(new TimeSpan(30, 0, 0, 0), token);
|
await reportService.DeleteAllOldReportsAsync(TimeSpan.FromDays(30), token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,17 +192,13 @@ namespace AsbCloudInfrastructure.Services
|
|||||||
|
|
||||||
public async Task<int> DeleteAllOldReportsAsync(TimeSpan lifetime, CancellationToken token)
|
public async Task<int> DeleteAllOldReportsAsync(TimeSpan lifetime, CancellationToken token)
|
||||||
{
|
{
|
||||||
var lifeTimeStartDate = DateTime.UtcNow.Date.Add(-lifetime);
|
var lifeTimeStartDate = DateTime.UtcNow.Date - lifetime;
|
||||||
var fileIds = db.ReportProperties
|
var fileIds = await db.ReportProperties
|
||||||
.Where(r => r.File.UploadDate.Date < lifeTimeStartDate)
|
.Where(r => r.File.UploadDate.Date < lifeTimeStartDate)
|
||||||
.Select(r => r.IdFile);
|
.Select(r => r.IdFile)
|
||||||
|
.ToArrayAsync(token);
|
||||||
|
|
||||||
if (fileIds.Any())
|
return await fileService.DeleteAsync(fileIds, token);
|
||||||
{
|
|
||||||
return await fileService.DeleteAsync(fileIds, token);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user