(self, time: Optional[int] = None, blocking_time: float = 0.5)
| 240 | ) |
| 241 | |
| 242 | def maintenance(self, time: Optional[int] = None, blocking_time: float = 0.5): |
| 243 | connection = sqlite3.connect(self.database) |
| 244 | cursor = connection.cursor() |
| 245 | connection.enable_load_extension(True) # Enable loading of extensions |
| 246 | connection.execute( |
| 247 | "PRAGMA foreign_keys = ON;" |
| 248 | ) # Need for working with foreign keys in db |
| 249 | connection.execute( |
| 250 | "PRAGMA journal_mode=WAL;" |
| 251 | ) # Need to properly work with ZSTD compression |
| 252 | connection.execute("PRAGMA auto_vacuum=full;") # Same as above thing |
| 253 | |
| 254 | if sqlite_zstd is not None: |
| 255 | sqlite_zstd.load(connection) |
| 256 | |
| 257 | with connection: |
| 258 | if time is not None: |
| 259 | cursor.execute( |
| 260 | "SELECT zstd_incremental_maintenance(?, ?);", (time, blocking_time) |
| 261 | ) |
| 262 | else: |
| 263 | cursor.execute( |
| 264 | "SELECT zstd_incremental_maintenance(null, ?);", (blocking_time,) |
| 265 | ) |
| 266 | cursor.execute("VACUUM") |
| 267 | cursor.execute("ANALYZE") |
| 268 | |
| 269 | cursor.close() |
| 270 | connection.close() |
| 271 | |
| 272 | def maintenance_thread(self): |
| 273 | maintenance_thread = threading.Thread(target=self.maintenance, daemon=True) |
no test coverage detected