forked from platypush/platypush
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.
This commit is contained in:
parent
72617b4b75
commit
2aa8778078
1 changed files with 5 additions and 10 deletions
|
@ -87,20 +87,14 @@ class EntitiesEngine(Thread):
|
||||||
(entity.name, entity.plugin)
|
(entity.name, entity.plugin)
|
||||||
] = e
|
] = 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:
|
with self._entities_cache_lock:
|
||||||
cached_entity = self._get_cached_entity(new_entity)
|
cached_entity = self._get_cached_entity(new_entity)
|
||||||
if cached_entity:
|
if cached_entity and cached_entity.get('id'):
|
||||||
if cached_entity.get('id'):
|
new_entity.id = cached_entity['id']
|
||||||
new_entity.id = cached_entity['id']
|
|
||||||
if cached_entity == self._cache_repr(new_entity):
|
|
||||||
return False
|
|
||||||
|
|
||||||
if new_entity.id:
|
if new_entity.id:
|
||||||
self._cache_entities(new_entity)
|
self._cache_entities(new_entity)
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
def _init_entities_cache(self):
|
def _init_entities_cache(self):
|
||||||
with self._get_db().get_session() as session:
|
with self._get_db().get_session() as session:
|
||||||
entities = session.query(Entity).all()
|
entities = session.query(Entity).all()
|
||||||
|
@ -113,7 +107,8 @@ class EntitiesEngine(Thread):
|
||||||
self.logger.info('Entities cache initialized')
|
self.logger.info('Entities cache initialized')
|
||||||
|
|
||||||
def _process_event(self, entity: Entity):
|
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))
|
get_bus().post(EntityUpdateEvent(entity=entity))
|
||||||
|
|
||||||
def post(self, *entities: Entity):
|
def post(self, *entities: Entity):
|
||||||
|
|
Loading…
Reference in a new issue