(
self, cache_dir_prefix: str, set_journal_mode: bool = False, num_shards: int = 1
)
| 178 | |
| 179 | class SqliteMetadataStore(MetadataStore): |
| 180 | def __init__( |
| 181 | self, cache_dir_prefix: str, set_journal_mode: bool = False, num_shards: int = 1 |
| 182 | ) -> None: |
| 183 | # We check startswith instead of equality because the version |
| 184 | # will have already been appended by the time the cache dir is |
| 185 | # passed here. |
| 186 | self.dbs: list[sqlite3.Connection] = [] |
| 187 | self.num_shards = num_shards |
| 188 | self.dirty_shards: set[int] = set() |
| 189 | if cache_dir_prefix.startswith(os.devnull): |
| 190 | return |
| 191 | |
| 192 | os.makedirs(cache_dir_prefix, exist_ok=True) |
| 193 | if num_shards <= 1: |
| 194 | self.dbs.append( |
| 195 | connect_db(os_path_join(cache_dir_prefix, "cache.db"), set_journal_mode) |
| 196 | ) |
| 197 | else: |
| 198 | for i in range(num_shards): |
| 199 | self.dbs.append( |
| 200 | connect_db(os_path_join(cache_dir_prefix, f"cache.{i}.db"), set_journal_mode) |
| 201 | ) |
| 202 | |
| 203 | def _shard_index(self, name: str) -> int: |
| 204 | if self.num_shards <= 1: |
nothing calls this directly
no test coverage detected