[#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.
This commit is contained in:
Fabio Manganiello 2024-09-02 02:20:39 +02:00
parent 90a953b738
commit 26f491025a
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -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):