fix logic
This commit is contained in:
parent
691686216e
commit
461790c1c1
1 changed files with 10 additions and 12 deletions
|
|
@ -247,16 +247,6 @@ public class ImportBackgroundService : BackgroundService
|
||||||
var imported = await _context.RecruitImports.AsQueryable()
|
var imported = await _context.RecruitImports.AsQueryable()
|
||||||
.Include(x => x.ImportHostories)
|
.Include(x => x.ImportHostories)
|
||||||
.Include(x => x.ImportFile)
|
.Include(x => x.ImportFile)
|
||||||
.Include(x => x.Recruits)
|
|
||||||
.ThenInclude(x => x.Addresses)
|
|
||||||
.Include(x => x.Recruits)
|
|
||||||
.ThenInclude(x => x.Occupations)
|
|
||||||
.Include(x => x.Recruits)
|
|
||||||
.ThenInclude(x => x.Certificates)
|
|
||||||
.Include(x => x.Recruits)
|
|
||||||
.ThenInclude(x => x.Educations)
|
|
||||||
.Include(x => x.Recruits)
|
|
||||||
.ThenInclude(x => x.Payments)
|
|
||||||
.FirstOrDefaultAsync(x => x.Id == job.RecruitImportId);
|
.FirstOrDefaultAsync(x => x.Id == job.RecruitImportId);
|
||||||
|
|
||||||
if (imported == null) throw new Exception("RecruitImport not found");
|
if (imported == null) throw new Exception("RecruitImport not found");
|
||||||
|
|
@ -281,8 +271,9 @@ public class ImportBackgroundService : BackgroundService
|
||||||
|
|
||||||
int row = 2;
|
int row = 2;
|
||||||
int batchCount = 0;
|
int batchCount = 0;
|
||||||
const int batchSize = 100;
|
const int batchSize = 50;
|
||||||
int totalProcessed = 0;
|
int totalProcessed = 0;
|
||||||
|
var batchList = new List<Models.Recruits.Recruit>();
|
||||||
|
|
||||||
while (row <= totalRows)
|
while (row <= totalRows)
|
||||||
{
|
{
|
||||||
|
|
@ -410,7 +401,7 @@ public class ImportBackgroundService : BackgroundService
|
||||||
});
|
});
|
||||||
|
|
||||||
r.RecruitImport = imported;
|
r.RecruitImport = imported;
|
||||||
_context.Recruits.Add(r);
|
batchList.Add(r);
|
||||||
|
|
||||||
row++;
|
row++;
|
||||||
batchCount++;
|
batchCount++;
|
||||||
|
|
@ -418,13 +409,20 @@ public class ImportBackgroundService : BackgroundService
|
||||||
|
|
||||||
if (batchCount >= batchSize)
|
if (batchCount >= batchSize)
|
||||||
{
|
{
|
||||||
|
_context.Recruits.AddRange(batchList);
|
||||||
_context.SaveChanges();
|
_context.SaveChanges();
|
||||||
_context.ChangeTracker.Clear();
|
_context.ChangeTracker.Clear();
|
||||||
_context.Entry(imported).State = EntityState.Unchanged;
|
_context.Entry(imported).State = EntityState.Unchanged;
|
||||||
|
batchList.Clear();
|
||||||
batchCount = 0;
|
batchCount = 0;
|
||||||
_tracker.UpdateStatus(job.JobId, ImportJobStatus.Running, totalProcessed);
|
_tracker.UpdateStatus(job.JobId, ImportJobStatus.Running, totalProcessed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (batchList.Count > 0)
|
||||||
|
{
|
||||||
|
_context.Recruits.AddRange(batchList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_context.SaveChanges();
|
_context.SaveChanges();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue