Skip to content

Commit

Permalink
fix: really turn off SQLite journal files on 3.12+
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Sep 30, 2023
1 parent 604aafa commit 8624ce9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Unreleased
data files. Now they are always ignored, fixing `issue 1605`_. Thanks to
Brad Smith for suggesting fixes and providing detailed debugging.

- On Python 3.12+, we now disable SQLite writing journal files, which should be
a little faster.

.. _issue 1605: https://github.com/nedbat/coveragepy/pull/1605
.. _issue 1684: https://github.com/nedbat/coveragepy/issues/1684
.. _pull 1685: https://github.com/nedbat/coveragepy/pull/1685
Expand Down
10 changes: 10 additions & 0 deletions coverage/sqlitedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,18 @@ def _connect(self) -> None:

self.con.create_function("REGEXP", 2, lambda txt, pat: re.search(txt, pat) is not None)

# Turning off journal_mode can speed up writing. It can't always be
# disabled, so we have to be prepared for *-journal files elsewhere.
# In Python 3.12+, we can change the config to allow journal_mode=off.
if hasattr(sqlite3, "SQLITE_DBCONFIG_DEFENSIVE"):
# Turn off defensive mode, so that journal_mode=off can succeed.
self.con.setconfig( # type: ignore[attr-defined]
sqlite3.SQLITE_DBCONFIG_DEFENSIVE, False
)

# This pragma makes writing faster. It disables rollbacks, but we never need them.
self.execute_void("pragma journal_mode=off")

# This pragma makes writing faster. It can fail in unusual situations
# (https://github.com/nedbat/coveragepy/issues/1646), so use fail_ok=True
# to keep things going.
Expand Down

0 comments on commit 8624ce9

Please sign in to comment.