This commit is contained in:
@@ -4,14 +4,8 @@ using AyaNova.Api.ControllerHelpers;
|
||||
using AyaNova.Models;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using AyaNova.Models;
|
||||
using AyaNova.Biz;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Bogus;
|
||||
using AyaNova.Api.ControllerHelpers;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Linq;
|
||||
|
||||
|
||||
namespace AyaNova.Biz
|
||||
@@ -70,13 +64,39 @@ namespace AyaNova.Biz
|
||||
await JobsBiz.LogJobAsync(job.GId, $"Starting...");
|
||||
apiServerState.SetOpsOnly("Attachment file maintenance");
|
||||
|
||||
//JObject jobData = JObject.Parse(job.JobInfo);
|
||||
// var seedLevel = (Seeder.Level.SeedLevel)jobData["seedLevel"].Value<int>();
|
||||
// var timeZoneOffset = jobData["timeZoneOffset"].Value<decimal>();
|
||||
// var seed = new Util.Seeder();
|
||||
// await seed.SeedDatabaseAsync(seedLevel, job.GId, timeZoneOffset);
|
||||
|
||||
// EXISTENCE CHECK
|
||||
//iterate all records in chunks
|
||||
bool moreRecords = true;
|
||||
int skip = 0;
|
||||
int chunkSize = 100;
|
||||
do
|
||||
{
|
||||
var chunk = await ct.FileAttachment.AsNoTracking().OrderBy(z => z.Id).Skip(skip).Take(chunkSize).Select(z => new NameIdItem { Id = z.Id, Name = z.StoredFileName }).ToListAsync();
|
||||
if (chunk.Count < chunkSize)
|
||||
{
|
||||
//we've reached the end
|
||||
moreRecords = false;
|
||||
}
|
||||
skip += chunkSize;
|
||||
foreach (NameIdItem i in chunk)
|
||||
{
|
||||
//Does file exists where it's supposed to be?
|
||||
if (!FileUtil.AttachmentFileExists(i.Name))
|
||||
{
|
||||
var f = await ct.FileAttachment.FirstOrDefaultAsync(z => z.Id == i.Id);
|
||||
if (f != null)
|
||||
{
|
||||
f.Exists = false;
|
||||
await ct.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} while (moreRecords);
|
||||
// long totalRecs = await ct.FileAttachment.LongCountAsync();
|
||||
|
||||
|
||||
|
||||
// iterate FileAttachment records, if physically present then flag as such
|
||||
// make sure it has a short circuit that if there are NO files physically then all are out of sync
|
||||
// this scenario is someone moving a db and not moving physical files
|
||||
|
||||
Reference in New Issue
Block a user