From 67d933a206b382d9e058907bf5896b09faf778bd Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sun, 18 Nov 2018 07:57:44 +0100 Subject: [PATCH] fix douple elements --- openslides/utils/cache_providers.py | 20 +++++++++-------- tests/integration/utils/test_consumers.py | 26 +++++++++++++++++++++++ 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/openslides/utils/cache_providers.py b/openslides/utils/cache_providers.py index 991cb82dc..791ec2ce5 100644 --- a/openslides/utils/cache_providers.py +++ b/openslides/utils/cache_providers.py @@ -418,16 +418,18 @@ class MemmoryCacheProvider: else: cache_dict = self.restricted_data.get(user_id, {}) + all_element_ids: Set[str] = set() for data_change_id, element_ids in self.change_id_data.items(): - if data_change_id < change_id or (max_change_id > -1 and data_change_id > max_change_id): - continue - for element_id in element_ids: - element_json = cache_dict.get(element_id, None) - if element_json is None: - deleted_elements.append(element_id) - else: - collection_string, id = split_element_id(element_id) - changed_elements[collection_string].append(element_json.encode()) + if data_change_id >= change_id and (max_change_id == -1 or data_change_id <= max_change_id): + all_element_ids.update(element_ids) + + for element_id in all_element_ids: + element_json = cache_dict.get(element_id, None) + if element_json is None: + deleted_elements.append(element_id) + else: + collection_string, id = split_element_id(element_id) + changed_elements[collection_string].append(element_json.encode()) return changed_elements, deleted_elements async def del_restricted_data(self, user_id: int) -> None: diff --git a/tests/integration/utils/test_consumers.py b/tests/integration/utils/test_consumers.py index edbccff14..642823305 100644 --- a/tests/integration/utils/test_consumers.py +++ b/tests/integration/utils/test_consumers.py @@ -359,6 +359,32 @@ async def test_send_connect_twice_with_clear_change_id_cache_same_change_id_then assert response2.get('content')['all_data'] +@pytest.mark.asyncio +async def test_request_changed_elements_no_douple_elements(communicator): + """ + Test, that when an elements is changed twice, it is only returned + onces when ask a range of change ids. + + Test when all_data is false + """ + await set_config('general_system_enable_anonymous', True) + await communicator.connect() + # Change element twice + await set_config('general_event_name', 'Test Event') + await set_config('general_event_name', 'Other value') + # Ask for all elements + await communicator.send_json_to({'type': 'getElements', 'content': {'change_id': 2}, 'id': 'test_id'}) + + response = await communicator.receive_json_from() + type = response.get('type') + content = response.get('content') + assert type == 'autoupdate' + assert not response.get('content')['all_data'] + config_ids = [e['id'] for e in content['changed']['core/config']] + # test that config_ids are unique + assert len(config_ids) == len(set(config_ids)) + + @pytest.mark.asyncio async def test_send_invalid_get_elements(communicator): await set_config('general_system_enable_anonymous', True)