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
This commit is contained in:
Russell Ballestrini 2024-10-06 19:35:29 -04:00
parent 41ab711fe3
commit 73faf89fed

View file

@ -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()