From df4bbafb208278cc9c230f5883155f5282136164 Mon Sep 17 00:00:00 2001 From: ychung-mot Date: Tue, 4 Jun 2024 09:14:05 -0700 Subject: [PATCH] chore: performance --- .../Repositories/UploadDeliveryRepository.cs | 9 +++++++++ server/StrDss.Model/UploadLineToProcess.cs | 8 ++++++++ server/StrDss.Service/RentalListingReportService.cs | 10 ++++++++++ 3 files changed, 27 insertions(+) create mode 100644 server/StrDss.Model/UploadLineToProcess.cs diff --git a/server/StrDss.Data/Repositories/UploadDeliveryRepository.cs b/server/StrDss.Data/Repositories/UploadDeliveryRepository.cs index 82c7b8d2..6db78e28 100644 --- a/server/StrDss.Data/Repositories/UploadDeliveryRepository.cs +++ b/server/StrDss.Data/Repositories/UploadDeliveryRepository.cs @@ -15,6 +15,7 @@ public interface IUploadDeliveryRepository Task GetRentalReportUploadToProcessAsync(); Task GetRentalListingErrorLines(long uploadId); Task GetUploadLineAsync(long uploadId, string orgCd, string listingId); + Task> GetUploadLinesToProcessAsync(long uploadId); } public class UploadDeliveryRepository : RepositoryBase, IUploadDeliveryRepository @@ -63,6 +64,14 @@ public async Task IsDuplicateRentalReportUploadAsnyc(DateOnly periodYm, lo return line; } + public async Task> GetUploadLinesToProcessAsync(long uploadId) + { + return await _dbContext.DssUploadLines.AsNoTracking() + .Where(x => x.IncludingUploadDeliveryId == uploadId && x.IsProcessed == false) + .Select(x => new UploadLineToProcess { ListingId = x.SourceRecordNo, OrgCd = x.SourceOrganizationCd }) + .ToListAsync(); + } + public async Task GetRentalListingErrorLines(long uploadId) { //todo: data control diff --git a/server/StrDss.Model/UploadLineToProcess.cs b/server/StrDss.Model/UploadLineToProcess.cs new file mode 100644 index 00000000..e9c0f4e1 --- /dev/null +++ b/server/StrDss.Model/UploadLineToProcess.cs @@ -0,0 +1,8 @@ +namespace StrDss.Model +{ + public class UploadLineToProcess + { + public string OrgCd { get; set; } = ""; + public string ListingId { get; set; } = ""; + } +} diff --git a/server/StrDss.Service/RentalListingReportService.cs b/server/StrDss.Service/RentalListingReportService.cs index 39926d29..bdc3bfbe 100644 --- a/server/StrDss.Service/RentalListingReportService.cs +++ b/server/StrDss.Service/RentalListingReportService.cs @@ -322,6 +322,8 @@ private async Task ProcessRentalReportUploadAsync(DssUploadDelivery upload) _unitOfWork.Commit(); } + var linesToProcess = await _uploadRepo.GetUploadLinesToProcessAsync(upload.UploadDeliveryId); + var errors = new Dictionary>(); var csvConfig = CsvHelperUtils.GetConfig(errors, false); @@ -342,6 +344,14 @@ private async Task ProcessRentalReportUploadAsync(DssUploadDelivery upload) var row = csv.GetRecord(); //it has been parsed once, so no exception expected. + var exists = linesToProcess.Any(x => x.OrgCd == row.OrgCd && x.ListingId == row.ListingId); + + if (!exists) + { + _logger.LogInformation($"Skipping listing - ({row.OrgCd} - {row.ListingId})"); + continue; + } + var uploadLine = await _uploadRepo.GetUploadLineAsync(upload.UploadDeliveryId, row.OrgCd, row.ListingId); if (uploadLine == null || uploadLine.IsProcessed)