chore: code clean-up

This commit is contained in:
Vlad Stan 2023-01-31 11:26:03 +02:00
parent 2d741c8627
commit eb443902c2
2 changed files with 0 additions and 10 deletions

View file

@ -15,13 +15,11 @@ class NostrClientManager:
def add_client(self, client: "NostrClientConnection"): def add_client(self, client: "NostrClientConnection"):
setattr(client, "broadcast_event", self.broadcast_event) setattr(client, "broadcast_event", self.broadcast_event)
self.clients.append(client) self.clients.append(client)
print("### client count:", len(self.clients))
def remove_client(self, client: "NostrClientConnection"): def remove_client(self, client: "NostrClientConnection"):
self.clients.remove(client) self.clients.remove(client)
async def broadcast_event(self, source: "NostrClientConnection", event: NostrEvent): async def broadcast_event(self, source: "NostrClientConnection", event: NostrEvent):
print("### broadcast_event", len(self.clients))
for client in self.clients: for client in self.clients:
if client != source: if client != source:
await client.notify_event(event) await client.notify_event(event)
@ -44,7 +42,6 @@ class NostrClientConnection:
resp = await self.__handle_message(data) resp = await self.__handle_message(data)
if resp: if resp:
for r in resp: for r in resp:
# print("### start send content: ", json.dumps(r))
await self.websocket.send_text(json.dumps(r)) await self.websocket.send_text(json.dumps(r))
except Exception as e: except Exception as e:
logger.warning(e) logger.warning(e)
@ -53,7 +50,6 @@ class NostrClientConnection:
for filter in self.filters: for filter in self.filters:
if filter.matches(event): if filter.matches(event):
r = [NostrEventType.EVENT, filter.subscription_id, dict(event)] r = [NostrEventType.EVENT, filter.subscription_id, dict(event)]
print("### notify send content: ", json.dumps(r))
await self.websocket.send_text(json.dumps(r)) await self.websocket.send_text(json.dumps(r))
async def __handle_message(self, data: List): async def __handle_message(self, data: List):
@ -86,9 +82,7 @@ class NostrClientConnection:
] ]
def __handle_close(self, subscription_id: str) -> None: def __handle_close(self, subscription_id: str) -> None:
print("### __handle_close", len(self.filters), subscription_id)
self.remove_filter(subscription_id) self.remove_filter(subscription_id)
print("### __handle_close", len(self.filters))
def remove_filter(self, subscription_id: str): def remove_filter(self, subscription_id: str):
self.filters = [f for f in self.filters if f.subscription_id != subscription_id] self.filters = [f for f in self.filters if f.subscription_id != subscription_id]

View file

@ -76,8 +76,6 @@ async def get_events(relay_id: str, filter: NostrFilter) -> List[NostrEvent]:
if filter.limit and type(filter.limit) == int and filter.limit > 0: if filter.limit and type(filter.limit) == int and filter.limit > 0:
query += f" LIMIT {filter.limit}" query += f" LIMIT {filter.limit}"
# print("### query: ", query)
# print("### values: ", tuple(values))
rows = await db.fetchall(query, tuple(values)) rows = await db.fetchall(query, tuple(values))
events = [] events = []
@ -86,8 +84,6 @@ async def get_events(relay_id: str, filter: NostrFilter) -> List[NostrEvent]:
event.tags = await get_event_tags(relay_id, event.id) event.tags = await get_event_tags(relay_id, event.id)
events.append(event) events.append(event)
print("### events: ", len(events))
return events return events