diff --git a/server/StrDss.Data/Repositories/RentalListingRepository.cs b/server/StrDss.Data/Repositories/RentalListingRepository.cs index 37b7c95a..287d112b 100644 --- a/server/StrDss.Data/Repositories/RentalListingRepository.cs +++ b/server/StrDss.Data/Repositories/RentalListingRepository.cs @@ -22,6 +22,7 @@ public interface IRentalListingRepository Task GetRetalListingExportAsync(long extractId); Task ConfirmAddressAsync(long rentalListingId); Task UpdateAddressAsync(UpdateListingAddressDto dto); + DateTime GetLatestRentalListingExportTime(); } public class RentalListingRepository : RepositoryBase, IRentalListingRepository { @@ -539,5 +540,17 @@ public async Task UpdateAddressAsync(UpdateListingAddressDto d return listing; } + + public DateTime GetLatestRentalListingExportTime() + { + if (_dbContext.DssRentalListingExtracts.Any()) + { + return _dbContext.DssRentalListingExtracts.Max(x => x.UpdDtm); + } + else + { + return DateTime.UtcNow.AddDays(-1); + } + } } } diff --git a/server/StrDss.Service/RentalListingService.cs b/server/StrDss.Service/RentalListingService.cs index 931f71e2..bfd1e47b 100644 --- a/server/StrDss.Service/RentalListingService.cs +++ b/server/StrDss.Service/RentalListingService.cs @@ -93,6 +93,17 @@ private void ProcessHosts(RentalListingViewDto listing, bool clearHosts = false) public async Task CreateRentalListingExportFiles() { + // Throttle export frequency: Prevent running if less than 2 hours since last export + var latestExtractTime = _listingRepo.GetLatestRentalListingExportTime(); + var currentTime = DateTime.UtcNow; + var timeDifference = currentTime - latestExtractTime; + + if (timeDifference < TimeSpan.FromHours(2)) + { + _logger.LogInformation("Skipping CreateRentalListingExportFiles: Last export was {TimeDifference:hh\\:mm\\:ss} ago, less than 2 hours", timeDifference); + return; + } + var listingIds = await _listingRepo.GetRentalListingIdsToExport(); var headers = RentalListingExport.GetHeadersAsCsv();