From d245a0b2c8b2b9854ac6a5c98b8b49840285a3dd Mon Sep 17 00:00:00 2001 From: ychung-mot Date: Tue, 4 Jun 2024 08:50:44 -0700 Subject: [PATCH] chore: peformance --- .../StrDss.Data/Repositories/UploadDeliveryRepository.cs | 7 +++---- server/StrDss.Hangfire/Program.cs | 2 +- server/StrDss.Service/Hangfire/HangfireJobs.cs | 2 +- server/StrDss.Service/Hangfire/SkipSameJobAttribute.cs | 1 + server/StrDss.Service/RentalListingReportService.cs | 8 ++++---- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/server/StrDss.Data/Repositories/UploadDeliveryRepository.cs b/server/StrDss.Data/Repositories/UploadDeliveryRepository.cs index 5c3531e3..82c7b8d2 100644 --- a/server/StrDss.Data/Repositories/UploadDeliveryRepository.cs +++ b/server/StrDss.Data/Repositories/UploadDeliveryRepository.cs @@ -12,7 +12,7 @@ public interface IUploadDeliveryRepository { Task IsDuplicateRentalReportUploadAsnyc(DateOnly periodYm, long orgId, string hashValue); Task AddUploadDeliveryAsync(DssUploadDelivery upload); - Task> GetRentalReportUploadsToProcessAsync(); + Task GetRentalReportUploadToProcessAsync(); Task GetRentalListingErrorLines(long uploadId); Task GetUploadLineAsync(long uploadId, string orgCd, string listingId); } @@ -35,16 +35,15 @@ public async Task IsDuplicateRentalReportUploadAsnyc(DateOnly periodYm, lo .AnyAsync(x => x.ReportPeriodYm == periodYm && x.ProvidingOrganizationId == orgId && x.SourceHashDsc == hashValue); } - public async Task> GetRentalReportUploadsToProcessAsync() + public async Task GetRentalReportUploadToProcessAsync() { return await _dbSet - //.Include(x => x.DssUploadLines.Where(line => !line.IsProcessed)) .Include(x => x.ProvidingOrganization) .Where(x => x.DssUploadLines.Any(line => !line.IsProcessed)) .OrderBy(x => x.ProvidingOrganizationId) .ThenBy(x => x.ReportPeriodYm) .ThenBy(x => x.UpdDtm) //Users can upload the same listing multiple times. The processing of these listings follows a first-come, first-served approach. - .ToListAsync(); + .FirstOrDefaultAsync(); } public async Task GetUploadLineAsync(long uploadId, string orgCd, string listingId) diff --git a/server/StrDss.Hangfire/Program.cs b/server/StrDss.Hangfire/Program.cs index 7313cdfe..dc5e9a75 100644 --- a/server/StrDss.Hangfire/Program.cs +++ b/server/StrDss.Hangfire/Program.cs @@ -161,7 +161,7 @@ app.UseHangfireDashboard(); // make sure this is after app.UseHangfireDashboard() -RecurringJob.AddOrUpdate("Process Rental Listing Report", job => job.ProcessRentalListingReports(), "*/10 * * * *"); +RecurringJob.AddOrUpdate("Process Rental Listing Report", job => job.ProcessRentalListingReports(), "0 0/3 * * *"); RecurringJob.AddOrUpdate("Process Takedown Request Batch Emails", job => job.ProcessTakedownRequestBatchEmails(), "50 6 * * *"); app.Run(); diff --git a/server/StrDss.Service/Hangfire/HangfireJobs.cs b/server/StrDss.Service/Hangfire/HangfireJobs.cs index ed713af8..4b090e82 100644 --- a/server/StrDss.Service/Hangfire/HangfireJobs.cs +++ b/server/StrDss.Service/Hangfire/HangfireJobs.cs @@ -18,7 +18,7 @@ public HangfireJobs(IRentalListingReportService listingService, IDelistingServic [AutomaticRetry(Attempts = 0)] public async Task ProcessRentalListingReports() { - await _linstingService.ProcessRentalReportUploadsAsync(); + await _linstingService.ProcessRentalReportUploadAsync(); } [Queue("default")] diff --git a/server/StrDss.Service/Hangfire/SkipSameJobAttribute.cs b/server/StrDss.Service/Hangfire/SkipSameJobAttribute.cs index b997536e..3281d32d 100644 --- a/server/StrDss.Service/Hangfire/SkipSameJobAttribute.cs +++ b/server/StrDss.Service/Hangfire/SkipSameJobAttribute.cs @@ -50,6 +50,7 @@ public void OnCreating(CreatingContext context) if (jobFingerprint != fingerprint) continue; + Console.WriteLine($"Cancelling {fingerprint} at {DateTime.UtcNow}"); context.Canceled = true; return; diff --git a/server/StrDss.Service/RentalListingReportService.cs b/server/StrDss.Service/RentalListingReportService.cs index d47d1945..39926d29 100644 --- a/server/StrDss.Service/RentalListingReportService.cs +++ b/server/StrDss.Service/RentalListingReportService.cs @@ -26,7 +26,7 @@ public interface IRentalListingReportService { Task>> ValidateAndParseUploadAsync(string reportPeriod, long orgId, string hashValue, TextReader textReader, List lines); Task>> UploadRentalReport(string reportPeriod, long orgId, Stream stream); - Task ProcessRentalReportUploadsAsync(); + Task ProcessRentalReportUploadAsync(); Task> GetRentalListingUploadHistory(long? platformId, int pageSize, int pageNumber, string orderBy, string direction); Task GetRentalListingErrorFile(long uploadId); } @@ -288,11 +288,11 @@ private bool CheckCommonMandatoryFields(string[] headers, string[] mandatoryFiel return errors.Count == 0; } - public async Task ProcessRentalReportUploadsAsync() + public async Task ProcessRentalReportUploadAsync() { - var uploads = await _uploadRepo.GetRentalReportUploadsToProcessAsync(); + var upload = await _uploadRepo.GetRentalReportUploadToProcessAsync(); - foreach (var upload in uploads) + if (upload != null) { await ProcessRentalReportUploadAsync(upload); }