From 8c81fe5c5e837c9486fee8468d395493f5da8687 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 4 Jan 2025 02:36:06 +0300 Subject: [PATCH] more correct way optimizing sqlite database --- ubot.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ubot.py b/ubot.py index 4822785..4f66d02 100644 --- a/ubot.py +++ b/ubot.py @@ -115,12 +115,19 @@ async def main(): )''') conn.commit() logger.debug('sqlite3 database initialized') - logger.debug('optimizing database...') - c.execute('PRAGMA optimize') + c.execute('PRAGMA optimize=0x10002') c.execute('PRAGMA journal_mode = WAL') c.execute('PRAGMA synchronous = normal') + logger.debug('Vacuuming database...') c.execute('VACUUM') - logger.debug('optimized') + logger.debug('Vacuum done') + + async def optimize_sqlite_db(): + while True: + c.execute('PRAGMA optimize') + logger.debug('database optimized') + await asyncio.sleep(12 * 60 * 60) + asyncio.ensure_future(optimize_sqlite_db()) ####################################################################