summary refs log tree commit diff
diff options
context:
space:
mode:
authorAndrew Morgan <andrew@amorgan.xyz>2021-12-08 19:02:13 +0000
committerAndrew Morgan <andrewm@element.io>2022-03-10 15:50:58 +0000
commit88c4e7369db621d8efb898720b5eb5a865af1c54 (patch)
treee427fe1ce0fddeb4aee7047d3631a9afef648dfd
parentMove DeviceLists type to synapse.types (diff)
downloadsynapse-88c4e7369db621d8efb898720b5eb5a865af1c54.tar.xz
Switch DeviceLists to containing Sets, which allows item deletes
In the next commit, we'll be merging one DeviceList into another. This
will require the ability to remove items by value, which Collection does
not provide, while a mutable structure such as Set does. Set was chosen to
to remove duplicate user IDs.
-rw-r--r--synapse/handlers/sync.py2
-rw-r--r--synapse/types.py15
2 files changed, 11 insertions, 6 deletions
diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py

index 7ad9870c75..90dca47b77 100644 --- a/synapse/handlers/sync.py +++ b/synapse/handlers/sync.py
@@ -1356,7 +1356,7 @@ class SyncHandler: return DeviceLists(changed=users_that_have_changed, left=newly_left_users) else: - return DeviceLists(changed=[], left=[]) + return DeviceLists() async def _generate_sync_entry_for_to_device( self, sync_result_builder: "SyncResultBuilder" diff --git a/synapse/types.py b/synapse/types.py
index ed718995ea..5a315a9f25 100644 --- a/synapse/types.py +++ b/synapse/types.py
@@ -19,13 +19,13 @@ from typing import ( TYPE_CHECKING, Any, ClassVar, - Collection, Dict, List, Mapping, Match, MutableMapping, Optional, + Set, Tuple, Type, TypeVar, @@ -748,12 +748,17 @@ class ReadReceipt: class DeviceLists: """ Attributes: - changed: List of user_ids whose devices may have changed - left: List of user_ids whose devices we no longer track + changed: user_ids whose devices may have changed + left: user_ids whose devices we no longer track """ - changed: Collection[str] - left: Collection[str] + # We need to use a factory here, otherwise `set` is not evaluated at + # object instantiation, but instead at class definition instantiation. + # The latter happening only once, thus always giving you the same sets + # across multiple DeviceLists instances. + # Also see: don't define mutable default arguments. + changed: Set[str] = attr.ib(factory=set) + left: Set[str] = attr.ib(factory=set) def __bool__(self) -> bool: return bool(self.changed or self.left)