From aaeb85db61bfb6c59177dc7edb2f1d0260f50949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Sat, 20 Jan 2018 09:45:02 +0100 Subject: [PATCH] Split send_data channel into send_data_projector and send_data_site for projector prioritization. Fixed #3426. --- openslides/routing.py | 6 ++-- openslides/utils/autoupdate.py | 16 ++++++++-- tests/integration/utils/test_autoupdate.py | 35 +++++++++++++++++----- 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/openslides/routing.py b/openslides/routing.py index d2f144f73..ff3c7f80e 100644 --- a/openslides/routing.py +++ b/openslides/routing.py @@ -1,7 +1,8 @@ from channels.routing import include, route from openslides.utils.autoupdate import ( - send_data, + send_data_projector, + send_data_site, ws_add_projector, ws_add_site, ws_disconnect_projector, @@ -23,5 +24,6 @@ site_routing = [ channel_routing = [ include(projector_routing, path=r'^/ws/projector/(?P\d+)/$'), include(site_routing, path=r'^/ws/site/$'), - route("autoupdate.send_data", send_data), + route("autoupdate.send_data_projector", send_data_projector), + route("autoupdate.send_data_site", send_data_site), ] diff --git a/openslides/utils/autoupdate.py b/openslides/utils/autoupdate.py index c804f4f7d..d9b39f4af 100644 --- a/openslides/utils/autoupdate.py +++ b/openslides/utils/autoupdate.py @@ -245,9 +245,9 @@ def ws_disconnect_projector(message: Any, projector_id: int) -> None: Group('projector-{}'.format(projector_id)).discard(message.reply_channel) -def send_data(message: ChannelMessageFormat) -> None: +def send_data_projector(message: ChannelMessageFormat) -> None: """ - Informs all site users and projector clients about changed data. + Informs all projector clients about changed data. """ collection_elements = from_channel_message(message) @@ -277,6 +277,13 @@ def send_data(message: ChannelMessageFormat) -> None: Group('projector-{}'.format(projector.pk)).send, {'text': json.dumps(output)}) + +def send_data_site(message: ChannelMessageFormat) -> None: + """ + Informs all site users about changed data. + """ + collection_elements = from_channel_message(message) + # Send data to site users. for user_id, channel_names in websocket_user_cache.get_all().items(): if not user_id: @@ -386,7 +393,10 @@ def send_autoupdate(collection_elements: List[CollectionElement]) -> None: """ if collection_elements: send_or_wait( - Channel('autoupdate.send_data').send, + Channel('autoupdate.send_data_projector').send, + to_channel_message(collection_elements)) + send_or_wait( + Channel('autoupdate.send_data_site').send, to_channel_message(collection_elements)) diff --git a/tests/integration/utils/test_autoupdate.py b/tests/integration/utils/test_autoupdate.py index 8e5aef7f3..c1a8ecd4f 100644 --- a/tests/integration/utils/test_autoupdate.py +++ b/tests/integration/utils/test_autoupdate.py @@ -29,7 +29,12 @@ class TestsInformChangedData(ChannelTestCase): inform_changed_data(topic) - channel_message = self.get_next_message('autoupdate.send_data', require=True) + channel_message = self.get_next_message('autoupdate.send_data_projector', require=True) + self.assertEqual(len(channel_message['elements']), 1) + self.assertEqual( + channel_message['elements'][0]['collection_string'], + 'topics/topic') + channel_message = self.get_next_message('autoupdate.send_data_site', require=True) self.assertEqual(len(channel_message['elements']), 1) self.assertEqual( channel_message['elements'][0]['collection_string'], @@ -44,7 +49,9 @@ class TestsInformChangedData(ChannelTestCase): inform_changed_data(topics) - channel_message = self.get_next_message('autoupdate.send_data', require=True) + channel_message = self.get_next_message('autoupdate.send_data_projector', require=True) + self.assertEqual(len(channel_message['elements']), 3) + channel_message = self.get_next_message('autoupdate.send_data_site', require=True) self.assertEqual(len(channel_message['elements']), 3) def test_change_with_non_root_rest_elements(self): @@ -59,7 +66,9 @@ class TestsInformChangedData(ChannelTestCase): inform_changed_data((assignment, poll)) - channel_message = self.get_next_message('autoupdate.send_data', require=True) + channel_message = self.get_next_message('autoupdate.send_data_projector', require=True) + self.assertEqual(len(channel_message['elements']), 1) + channel_message = self.get_next_message('autoupdate.send_data_site', require=True) self.assertEqual(len(channel_message['elements']), 1) def test_change_only_non_root_rest_element(self): @@ -73,7 +82,9 @@ class TestsInformChangedData(ChannelTestCase): inform_changed_data(poll) - channel_message = self.get_next_message('autoupdate.send_data', require=True) + channel_message = self.get_next_message('autoupdate.send_data_projector', require=True) + self.assertEqual(len(channel_message['elements']), 1) + channel_message = self.get_next_message('autoupdate.send_data_site', require=True) self.assertEqual(len(channel_message['elements']), 1) def test_change_no_autoupdate_model(self): @@ -90,14 +101,22 @@ class TestsInformChangedData(ChannelTestCase): with self.assertRaises(AssertionError): # self.get_next_message() with require=True raises a AssertionError # if there is no message in the channel - self.get_next_message('autoupdate.send_data', require=True) + self.get_next_message('autoupdate.send_data_projector', require=True) + + with self.assertRaises(AssertionError): + # self.get_next_message() with require=True raises a AssertionError + # if there is no message in the channel + self.get_next_message('autoupdate.send_data_site', require=True) def test_delete_one_element(self): channel_layers[DEFAULT_CHANNEL_LAYER].flush() inform_deleted_data([('topics/topic', 1)]) - channel_message = self.get_next_message('autoupdate.send_data', require=True) + channel_message = self.get_next_message('autoupdate.send_data_projector', require=True) + self.assertEqual(len(channel_message['elements']), 1) + self.assertTrue(channel_message['elements'][0]['deleted']) + channel_message = self.get_next_message('autoupdate.send_data_site', require=True) self.assertEqual(len(channel_message['elements']), 1) self.assertTrue(channel_message['elements'][0]['deleted']) @@ -106,5 +125,7 @@ class TestsInformChangedData(ChannelTestCase): inform_deleted_data([('topics/topic', 1), ('topics/topic', 2), ('testmodule/model', 1)]) - channel_message = self.get_next_message('autoupdate.send_data', require=True) + channel_message = self.get_next_message('autoupdate.send_data_projector', require=True) + self.assertEqual(len(channel_message['elements']), 3) + channel_message = self.get_next_message('autoupdate.send_data_site', require=True) self.assertEqual(len(channel_message['elements']), 3)