Skip to content

Commit

Permalink
Merge pull request #898 from koordinates/journal_mode
Browse files Browse the repository at this point in the history
Use journal_mode = WAL on annotations.db
  • Loading branch information
olsen232 committed Aug 17, 2023
2 parents bf5a2f7 + 2f7f3c1 commit 492e14d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ _When adding new entries to the changelog, please include issue/PR numbers where
- Better protection against XSS in the HTML diff viewer. [#884](https://github.com/koordinates/kart/pull/884)
- Speed-up: greatly reduces the time taken to update the index file after checking out LFS tiles to the working copy. [#880](https://github.com/koordinates/kart/pull/880)
- Adds `--with-dataset-types` option to `kart data ls` command (and deprecates `kart data version`). [#892](https://github.com/koordinates/kart/issues/892)
- Use `journal_mode = WAL` in annotations.db sqlite database. [#898](https://github.com/koordinates/kart/pull/898)

## 0.14.0

Expand Down
2 changes: 1 addition & 1 deletion kart/annotations/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def ignore_readonly_db(session):

@contextlib.contextmanager
def _annotations_session(db_path):
engine = sqlite_engine(db_path)
engine = sqlite_engine(db_path, journal_mode="WAL")
sm = sessionmaker(bind=engine)
inspector = sqlalchemy.inspect(engine)
is_readonly = None
Expand Down
6 changes: 4 additions & 2 deletions kart/sqlalchemy/gpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ class Db_GPKG(BaseDb):
preparer = SQLiteIdentifierPreparer(SQLiteDialect())

@classmethod
def create_engine(cls, path, **kwargs):
def create_engine(cls, path, *, journal_mode=None, **kwargs):
def _on_connect(pysqlite_conn, connection_record):
pysqlite_conn.isolation_level = None
pysqlite_conn.enable_load_extension(True)
pysqlite_conn.load_extension(spatialite_path)
pysqlite_conn.enable_load_extension(False)
dbcur = pysqlite_conn.cursor()
if journal_mode:
dbcur.execute(f"PRAGMA journal_mode = {journal_mode};")
dbcur.execute("SELECT EnableGpkgMode();")
dbcur.execute("PRAGMA foreign_keys = ON;")
dbcur.execute(f"PRAGMA cache_size = -{cls.GPKG_CACHE_SIZE_MiB * 1024};")
Expand Down Expand Up @@ -64,7 +66,7 @@ def list_tables(cls, sess, db_schema=None):

@classmethod
def pk_name(cls, sess, db_schema=None, table=None):
""" Find the primary key for a GeoPackage table """
"""Find the primary key for a GeoPackage table"""

# Requirement 150:
# A feature table or view SHALL have a column that uniquely identifies the
Expand Down
4 changes: 3 additions & 1 deletion kart/sqlalchemy/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
import sqlalchemy


def sqlite_engine(path):
def sqlite_engine(path, *, journal_mode=None):
"""
An engine for non-spatial, non-GPKG sqlite databases.
"""

def _on_connect(pysqlite_conn, connection_record):
pysqlite_conn.isolation_level = None
dbcur = pysqlite_conn.cursor()
if journal_mode:
dbcur.execute(f"PRAGMA journal_mode = {journal_mode};")
dbcur.execute("PRAGMA foreign_keys = ON;")

path = os.path.expanduser(path)
Expand Down

0 comments on commit 492e14d

Please sign in to comment.