Skip to content

Commit

Permalink
Merge pull request #362 from bcgov/june
Browse files Browse the repository at this point in the history
chore: performance
  • Loading branch information
ychung-mot authored Jun 4, 2024
2 parents 02526f0 + df4bbaf commit 072d23e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions server/StrDss.Data/Repositories/UploadDeliveryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public interface IUploadDeliveryRepository
Task<DssUploadDelivery?> GetRentalReportUploadToProcessAsync();
Task<DssUploadDelivery?> GetRentalListingErrorLines(long uploadId);
Task<DssUploadLine?> GetUploadLineAsync(long uploadId, string orgCd, string listingId);
Task<List<UploadLineToProcess>> GetUploadLinesToProcessAsync(long uploadId);
}

public class UploadDeliveryRepository : RepositoryBase<DssUploadDelivery>, IUploadDeliveryRepository
Expand Down Expand Up @@ -63,6 +64,14 @@ public async Task<bool> IsDuplicateRentalReportUploadAsnyc(DateOnly periodYm, lo
return line;
}

public async Task<List<UploadLineToProcess>> 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<DssUploadDelivery?> GetRentalListingErrorLines(long uploadId)
{
//todo: data control
Expand Down
8 changes: 8 additions & 0 deletions server/StrDss.Model/UploadLineToProcess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace StrDss.Model
{
public class UploadLineToProcess
{
public string OrgCd { get; set; } = "";
public string ListingId { get; set; } = "";
}
}
10 changes: 10 additions & 0 deletions server/StrDss.Service/RentalListingReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ private async Task ProcessRentalReportUploadAsync(DssUploadDelivery upload)
_unitOfWork.Commit();
}

var linesToProcess = await _uploadRepo.GetUploadLinesToProcessAsync(upload.UploadDeliveryId);

var errors = new Dictionary<string, List<string>>();
var csvConfig = CsvHelperUtils.GetConfig(errors, false);

Expand All @@ -342,6 +344,14 @@ private async Task ProcessRentalReportUploadAsync(DssUploadDelivery upload)

var row = csv.GetRecord<RentalListingRowUntyped>(); //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)
Expand Down

0 comments on commit 072d23e

Please sign in to comment.