Merge pull request #4021 from ostcar/fix_double_elements_in_autoupdate
fix douple elements
This commit is contained in:
commit
619a589731
@ -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:
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user