jupyter-server / jupyter_server_fileid

An extension that maintains file IDs for documents in a running Jupyter Server
https://jupyter-server-fileid.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
3 stars 12 forks source link

use a decorator to automatically commit after public methods #64

Open dlqqq opened 1 year ago

dlqqq commented 1 year ago

Problem

Forgetting to call self.con.commit() imperatively can be the source of a lot of silly bugs, as seen in https://github.com/jupyter-server/jupyter_server_fileid/pull/63.

Setting autocommit=True is bad for performance, as a single batched commit is significantly faster than multiple commits. The way this is currently being managed is that private methods never commit, and public methods should always commit right before returning the value. However, this currently needs to be done imperatively at every possible return point in each public method, which is fragile.

Proposed Solution

There should be a @commit decorator that wraps every public method.