Skip to content

Commit

Permalink
minor adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Trogious committed Feb 15, 2020
1 parent 2db352e commit 272aa71
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion model.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(self, websocket, register_req_id, view_name):
self.port = -1

def __repr__(self):
return '%s:%d' % (self.ip, self.port)
return '%s:%d,%d,%s' % (self.ip, self.port, self.req_id, self.view_name)

def __hash__(self):
return self.websocket.__hash__()
Expand Down
7 changes: 4 additions & 3 deletions server_wss.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,17 @@ def get_view_name(requested_view_name):
async def add_client(websocket, req_id, view_name):
async with Cached.clients_lock:
client = Client(websocket, req_id, view_name)
Cached.clients.discard(client)
Cached.clients.add(client)
logger.info('added: %s:%d,%s' % (client.ip, client.port, view_name))
logger.info('added: %s' % client)

@staticmethod
async def remove_client(websocket):
async with Cached.clients_lock:
remove = {client for client in Cached.clients if client.websocket == websocket}
for client in remove:
Cached.clients.discard(client)
logger.info('removed: %s:%d' % (client.ip, client.port))
logger.info('removed: %s:%d' % client)

@staticmethod
def filter_by_view(new_data, view_name):
Expand All @@ -133,7 +134,7 @@ async def notify_clients(new_data):
for client in Cached.clients:
logger.info('sending to %s' % (client))
try:
# TODO: add _after_hash indicator for views with sorting, for 'new'
# TODO: add _prev_hash indicator for views with sorting, for 'new'
# OPTIMIZE: do not send 'changed' and 'del' for hashes not present client's view
await client.websocket.send(prepare_response(get_json_response(client.req_id, new_data)))
except WebSocketException as e:
Expand Down

0 comments on commit 272aa71

Please sign in to comment.