From 26f491025a03d091467efc081f7d0c2f16c36aae Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Mon, 2 Sep 2024 02:20:39 +0200 Subject: [PATCH] [#341] Improvements on `procedures.save`. - Update the cached representation of the procedure asynchronously on the `publish_entities` callback. This prevents stale records from being loaded from the db before the entities engine has persisted the new ones. - Don't re-publish all entities when calling `procedures.status` at the end of `procedures.save`. This is both for performance reasons and to avoid sending to the entities engine stale representation of the data. --- platypush/plugins/procedures/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/platypush/plugins/procedures/__init__.py b/platypush/plugins/procedures/__init__.py index dde599c018..7b6aa4f36c 100644 --- a/platypush/plugins/procedures/__init__.py +++ b/platypush/plugins/procedures/__init__.py @@ -190,6 +190,9 @@ class ProceduresPlugin(RunnablePlugin, ProcedureEntityManager): ), } + def _on_entity_saved(*_, **__): + self._all_procedures[name] = proc_args + with self._status_lock: with self._db_session() as session: if old_name and old_name != name: @@ -202,11 +205,12 @@ class ProceduresPlugin(RunnablePlugin, ProcedureEntityManager): e, ) - self._all_procedures[name] = proc_args + self.publish_entities( + [_ProcedureWrapper(name=name, obj=proc_args)], + callback=_on_entity_saved, + ) - self.publish_entities([_ProcedureWrapper(name=name, obj=proc_args)]) - - return self.status() + return self.status(publish=False) @action def delete(self, name: str):