From 2aa8778078239088b34047e4c2568a4bda6ce5a5 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Tue, 12 Apr 2022 00:41:20 +0200 Subject: [PATCH] Do not process EntityUpdateEvents only in case of payload changes The UI relies on these events upon refresh to detect if a device is still reacheable. Therefore, we shouldn't mask them if we don't detect any changes with the current entity configuration/state. --- platypush/entities/_engine.py | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/platypush/entities/_engine.py b/platypush/entities/_engine.py index f82c70297..e7a72726f 100644 --- a/platypush/entities/_engine.py +++ b/platypush/entities/_engine.py @@ -87,20 +87,14 @@ class EntitiesEngine(Thread): (entity.name, entity.plugin) ] = e - def _entity_has_changes(self, new_entity: Entity) -> bool: + def _populate_entity_id_from_cache(self, new_entity: Entity): with self._entities_cache_lock: cached_entity = self._get_cached_entity(new_entity) - if cached_entity: - if cached_entity.get('id'): - new_entity.id = cached_entity['id'] - if cached_entity == self._cache_repr(new_entity): - return False - + if cached_entity and cached_entity.get('id'): + new_entity.id = cached_entity['id'] if new_entity.id: self._cache_entities(new_entity) - return True - def _init_entities_cache(self): with self._get_db().get_session() as session: entities = session.query(Entity).all() @@ -113,7 +107,8 @@ class EntitiesEngine(Thread): self.logger.info('Entities cache initialized') def _process_event(self, entity: Entity): - if self._entity_has_changes(entity) and entity.id: + self._populate_entity_id_from_cache(entity) + if entity.id: get_bus().post(EntityUpdateEvent(entity=entity)) def post(self, *entities: Entity):