Skip to content

Improve implicit DB transaction / enable autocommit #90

Description

@cpeel

The first select on a DB will start an implicit transaction and hold it open until it is either explicitly rolled back or committed, or automatically rolled back when the connection closes. This is not a recommended best practice as it can result in long-lived transactions, database locks, and table bloat if auto vacuum isn't able to remove objects.

ebookconverter creates long-lived DB connections at module load time, for example: Candidates.py:

ob = GutenbergDatabase.Objectbase(False)

Even though the module is only doing selects, it creates a transaction that is held open the entire time the process is running.

ebookconverter only does explicit transactions in BlueskyWriter.py, FacebookWriter.py, and MastodonWriter.py but even those aren't done correctly because the initial select starts the transaction on the connection that is ultimately rolled back.

One solution is to update libgutenberg.GutenbergDatabase.Database (raw DBAPI connection) and Objectbase (sqlalchemy connection) to allow those constructors to pass in the appropriate autocommit setting and then having ebookconverter use them. Then the explicit transactions in the above files can be removed as well.

References:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions