Migrate LocalDB to use SQLite database#502
Migrate LocalDB to use SQLite database#502paman7647 wants to merge 1 commit intoTeamUltroid:mainfrom
Conversation
Migrate LocalDB to use SQLite instead of localdb. Added methods for database operations and performance optimizations.
There was a problem hiding this comment.
Pull request overview
This PR migrates the fallback “LocalDB” implementation from the third-party localdb JSON-based storage to a SQLite-backed store, keeping the same high-level get/set/delete behavior when no Redis/Mongo/Postgres backend is configured.
Changes:
- Replaced
localdbdependency/installer path with a SQLite-based local database implementation. - Added SQLite schema initialization and basic CRUD operations for
LocalDB. - Updated the fallback log message to indicate SQLite is used.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| self.conn = sqlite3.connect(db_name, check_same_thread=False) | ||
| self.cursor = self.conn.cursor() | ||
|
|
||
| # Performance tweaks | ||
| self.cursor.execute("PRAGMA journal_mode=WAL;") | ||
| self.cursor.execute("PRAGMA synchronous=NORMAL;") |
There was a problem hiding this comment.
sqlite3.connect(..., check_same_thread=False) allows cross-thread access, but the class shares a single connection + cursor without any locking. Since udB is used inside run_async functions (ThreadPoolExecutor), concurrent calls can lead to sqlite3.ProgrammingError (recursive cursor use) or data corruption. Consider either (a) adding a threading.Lock/RLock and serializing all DB operations, and/or (b) not storing a shared self.cursor and instead using self.conn.execute(...) (creating a fresh cursor per call).
| else: | ||
| LOGS.critical( | ||
| "No DB requirement fullfilled!\nPlease install redis, mongo or sql dependencies...\nTill then using local file as database." | ||
| "No DB requirement fullfilled!\nPlease install redis, mongo or sql dependencies...\nTill then using SQLite as database." |
There was a problem hiding this comment.
Typo in log message: "fullfilled" should be "fulfilled".
| "No DB requirement fullfilled!\nPlease install redis, mongo or sql dependencies...\nTill then using SQLite as database." | |
| "No DB requirement fulfilled!\nPlease install redis, mongo or sql dependencies...\nTill then using SQLite as database." |
|
@paman7647 lol |
Migrate LocalDB to use SQLite instead of localdb. Added methods for database operations and performance optimizations.