mirror of
https://github.com/rightup/pyMC_Repeater.git
synced 2026-03-28 17:43:06 +01:00
Merge pull request #24 from rightup/feat/advert-dedupe
feat: add caching for known neighbors in RepeaterHandler to improve perf
This commit is contained in:
@@ -98,8 +98,8 @@ class RepeaterHandler(BaseHandler):
|
||||
self._transport_keys_cache_time = 0
|
||||
self._transport_keys_cache_ttl = 60 # Cache for 60 seconds
|
||||
|
||||
# Track last drop reason for better logging
|
||||
self._last_drop_reason = None
|
||||
self._known_neighbors = set()
|
||||
|
||||
self._start_background_tasks()
|
||||
|
||||
@@ -385,11 +385,16 @@ class RepeaterHandler(BaseHandler):
|
||||
|
||||
current_time = time.time()
|
||||
|
||||
# Check if this is a new neighbor
|
||||
current_neighbors = self.storage.get_neighbors() if self.storage else {}
|
||||
is_new_neighbor = pubkey not in current_neighbors
|
||||
|
||||
# Create advert record for storage
|
||||
if pubkey not in self._known_neighbors:
|
||||
# Only check database if not in cache
|
||||
current_neighbors = self.storage.get_neighbors() if self.storage else {}
|
||||
is_new_neighbor = pubkey not in current_neighbors
|
||||
|
||||
if is_new_neighbor:
|
||||
self._known_neighbors.add(pubkey)
|
||||
else:
|
||||
is_new_neighbor = False
|
||||
|
||||
advert_record = {
|
||||
"timestamp": current_time,
|
||||
"pubkey": pubkey,
|
||||
|
||||
Reference in New Issue
Block a user