From 4a1203b49290da2b10f9e1724a08750ca4002571 Mon Sep 17 00:00:00 2001 From: Egbert Bouman Date: Mon, 25 Nov 2024 15:55:45 +0100 Subject: [PATCH] Process health checks in single db session --- src/tribler/core/content_discovery/community.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/tribler/core/content_discovery/community.py b/src/tribler/core/content_discovery/community.py index 050b9fedce..733d6a7d89 100644 --- a/src/tribler/core/content_discovery/community.py +++ b/src/tribler/core/content_discovery/community.py @@ -178,12 +178,13 @@ async def on_torrents_health(self, peer: Peer, payload: TorrentsHealthPayload) - health_list = [HealthInfo(infohash, last_check=last_check, seeders=seeders, leechers=leechers) for infohash, seeders, leechers, last_check in health_tuples] + to_resolve = self.process_torrents_health(health_list) + for health_info in health_list: # Get a single result per infohash to avoid duplicates - with db_session: - self.composition.metadata_store.process_torrent_health(health_info) - infohash = hexlify(health_info.infohash).decode() - self.send_remote_select(peer=peer, infohash=infohash, last=1) + if health_info.infohash in to_resolve: + infohash = hexlify(health_info.infohash).decode() + self.send_remote_select(peer=peer, infohash=infohash, last=1) @db_session def process_torrents_health(self, health_list: list[HealthInfo]) -> set[bytes]: