From 94e59f08d2d0f0236efe022d4db71e6031e8d057 Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Tue, 7 Apr 2026 23:02:09 +0100 Subject: [PATCH] Always disable sync in SQLite cache --- mypy/build.py | 9 +++------ mypy/metastore.py | 15 +++++++-------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/mypy/build.py b/mypy/build.py index 98caaaec2dcf9..58289571bad60 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -877,7 +877,7 @@ def __init__( ] ) - self.metastore = create_metastore(options, parallel_worker) + self.metastore = create_metastore(options) # a mapping from source files to their corresponding shadow files # for efficient lookup @@ -1616,13 +1616,10 @@ def exclude_from_backups(target_dir: str) -> None: pass -def create_metastore(options: Options, parallel_worker: bool = False) -> MetadataStore: +def create_metastore(options: Options) -> MetadataStore: """Create the appropriate metadata store.""" if options.sqlite_cache: - # We use this flag in both coordinator and workers to speed up commits, - # see mypy.metastore.connect_db() for details. - sync_off = options.num_workers > 0 or parallel_worker - mds: MetadataStore = SqliteMetadataStore(_cache_dir_prefix(options), sync_off=sync_off) + mds: MetadataStore = SqliteMetadataStore(_cache_dir_prefix(options)) else: mds = FilesystemMetadataStore(_cache_dir_prefix(options)) return mds diff --git a/mypy/metastore.py b/mypy/metastore.py index 64839bf8a79c0..3d32ba29ae107 100644 --- a/mypy/metastore.py +++ b/mypy/metastore.py @@ -154,21 +154,20 @@ def close(self) -> None: """ -def connect_db(db_file: str, sync_off: bool = False) -> sqlite3.Connection: +def connect_db(db_file: str) -> sqlite3.Connection: import sqlite3.dbapi2 db = sqlite3.dbapi2.connect(db_file) - if sync_off: - # This is a bit unfortunate (as we may get corrupt cache after e.g. Ctrl + C), - # but without this flag, commits are *very* slow, especially when using HDDs, - # see https://www.sqlite.org/faq.html#q19 for details. - db.execute("PRAGMA synchronous=OFF") + # This is a bit unfortunate (as we may get corrupt cache after e.g. Ctrl + C), + # but without this flag, commits are *very* slow, especially when using HDDs, + # see https://www.sqlite.org/faq.html#q19 for details. + db.execute("PRAGMA synchronous=OFF") db.executescript(SCHEMA) return db class SqliteMetadataStore(MetadataStore): - def __init__(self, cache_dir_prefix: str, sync_off: bool = False) -> None: + def __init__(self, cache_dir_prefix: str) -> None: # We check startswith instead of equality because the version # will have already been appended by the time the cache dir is # passed here. @@ -177,7 +176,7 @@ def __init__(self, cache_dir_prefix: str, sync_off: bool = False) -> None: return os.makedirs(cache_dir_prefix, exist_ok=True) - self.db = connect_db(os_path_join(cache_dir_prefix, "cache.db"), sync_off=sync_off) + self.db = connect_db(os_path_join(cache_dir_prefix, "cache.db")) def _query(self, name: str, field: str) -> Any: # Raises FileNotFound for consistency with the file system version