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()
|
||||
.Include(x => x.ImportHostories)
|
||||
.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);
|
||||
|
||||
if (imported == null) throw new Exception("RecruitImport not found");
|
||||
|
|
@ -281,8 +271,9 @@ public class ImportBackgroundService : BackgroundService
|
|||
|
||||
int row = 2;
|
||||
int batchCount = 0;
|
||||
const int batchSize = 100;
|
||||
const int batchSize = 50;
|
||||
int totalProcessed = 0;
|
||||
var batchList = new List<Models.Recruits.Recruit>();
|
||||
|
||||
while (row <= totalRows)
|
||||
{
|
||||
|
|
@ -410,7 +401,7 @@ public class ImportBackgroundService : BackgroundService
|
|||
});
|
||||
|
||||
r.RecruitImport = imported;
|
||||
_context.Recruits.Add(r);
|
||||
batchList.Add(r);
|
||||
|
||||
row++;
|
||||
batchCount++;
|
||||
|
|
@ -418,13 +409,20 @@ public class ImportBackgroundService : BackgroundService
|
|||
|
||||
if (batchCount >= batchSize)
|
||||
{
|
||||
_context.Recruits.AddRange(batchList);
|
||||
_context.SaveChanges();
|
||||
_context.ChangeTracker.Clear();
|
||||
_context.Entry(imported).State = EntityState.Unchanged;
|
||||
batchList.Clear();
|
||||
batchCount = 0;
|
||||
_tracker.UpdateStatus(job.JobId, ImportJobStatus.Running, totalProcessed);
|
||||
}
|
||||
}
|
||||
|
||||
if (batchList.Count > 0)
|
||||
{
|
||||
_context.Recruits.AddRange(batchList);
|
||||
}
|
||||
}
|
||||
|
||||
_context.SaveChanges();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue