Merge pull request #3534 from normanjaeckel/BetterProjectorPrioritization

Split send_data channel into send_data_projector and send_data_site f…
This commit is contained in:
Emanuel Schütze 2018-01-21 09:23:19 +01:00 committed by GitHub
commit 3ac072d1a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 12 deletions

View File

@ -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<projector_id>\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),
]

View File

@ -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))

View File

@ -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)