From 73faf89fed652a0b823e92a4f7e9584273009a98 Mon Sep 17 00:00:00 2001 From: Russell Ballestrini Date: Sun, 6 Oct 2024 19:35:29 -0400 Subject: [PATCH] Optimize target verification by reducing unnecessary updates - Modified verify_target method to skip updating the target if the NamespaceRequest is already verified and the last verification was within the past day. - This change reduces unnecessary modifications to the target, improving efficiency and maintaining data integrity. - Added logging to indicate when target verification is skipped due to verification status. hopefully this: * lowers cpu usage, although it can't hurt. * reduces database churn and locking. modified: remarkbox/models/namespace_request.py --- remarkbox/models/namespace_request.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/remarkbox/models/namespace_request.py b/remarkbox/models/namespace_request.py index 49df562..839543f 100644 --- a/remarkbox/models/namespace_request.py +++ b/remarkbox/models/namespace_request.py @@ -57,6 +57,21 @@ class NamespaceRequest(RBase, Base): self.verified = False def verify_target(self, target): + """Verify the target only if not already verified or if a day has passed since last verification.""" + current_time = now_timestamp() + one_day_in_milliseconds = 24 * 60 * 60 * 1000 + + # Skip verification if already verified and last scrape was within a day + if ( + self.verified + and self.last_scrape_timestamp + and (current_time - self.last_scrape_timestamp) < one_day_in_milliseconds + ): + log.info( + f"Skipping target verification for verified namespace request id={self.id}" + ) + return None + self.target = target if self.scrape_target(): self.verify()