check membership instead of one update per peer

This commit is contained in:
Victor Shyba 2022-06-11 18:38:08 -03:00 committed by Victor Shyba
parent 443a1c32fa
commit be4c62cf32

View file

@ -148,9 +148,9 @@ class Crawler:
to_peer_id=self.get_from_peer(peer).peer_id) to_peer_id=self.get_from_peer(peer).peer_id)
for peer in peers for peer in peers
} }
for peer in peers: all_peer_ids = {peer.node_id for peer in peers if peer.node_id}
self.db.query(DHTPeer).filter(DHTPeer.address == peer.address, DHTPeer.udp_port == peer.udp_port).update( print(self.db.query(DHTPeer).filter(DHTPeer.node_id.in_(all_peer_ids)).update(
{DHTPeer.last_seen: datetime.datetime.utcnow()}) {DHTPeer.last_seen: datetime.datetime.utcnow()}))
self.db.query(DHTConnection).filter(DHTConnection.from_peer_id == db_peer.peer_id).delete() self.db.query(DHTConnection).filter(DHTConnection.from_peer_id == db_peer.peer_id).delete()
self.db.add_all(connections) self.db.add_all(connections)
self.db.commit() self.db.commit()