Merge pull request #4021 from ostcar/fix_double_elements_in_autoupdate
fix douple elements
This commit is contained in:
commit
619a589731
@ -418,10 +418,12 @@ class MemmoryCacheProvider:
|
|||||||
else:
|
else:
|
||||||
cache_dict = self.restricted_data.get(user_id, {})
|
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():
|
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):
|
if data_change_id >= change_id and (max_change_id == -1 or data_change_id <= max_change_id):
|
||||||
continue
|
all_element_ids.update(element_ids)
|
||||||
for element_id in element_ids:
|
|
||||||
|
for element_id in all_element_ids:
|
||||||
element_json = cache_dict.get(element_id, None)
|
element_json = cache_dict.get(element_id, None)
|
||||||
if element_json is None:
|
if element_json is None:
|
||||||
deleted_elements.append(element_id)
|
deleted_elements.append(element_id)
|
||||||
|
@ -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']
|
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
|
@pytest.mark.asyncio
|
||||||
async def test_send_invalid_get_elements(communicator):
|
async def test_send_invalid_get_elements(communicator):
|
||||||
await set_config('general_system_enable_anonymous', True)
|
await set_config('general_system_enable_anonymous', True)
|
||||||
|
Loading…
Reference in New Issue
Block a user