From 7d457a32f779083c085c7b28b2eb828b1ce4b660 Mon Sep 17 00:00:00 2001 From: Aharshi3614 Date: Tue, 2 Jun 2026 15:36:50 +0530 Subject: [PATCH 1/2] fix: add retry fallback for SQLite database lock --- backend/services/db_service.py | 40 ++++++++++++++++++++++---- backend/tests/test_db_lock_fallback.py | 8 ++++++ 2 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 backend/tests/test_db_lock_fallback.py diff --git a/backend/services/db_service.py b/backend/services/db_service.py index af3f88f..66d8ed9 100644 --- a/backend/services/db_service.py +++ b/backend/services/db_service.py @@ -7,6 +7,8 @@ import json import os from contextlib import contextmanager +import time +from sqlite3 import OperationalError DB_PATH = os.getenv("DB_PATH", "./data/localmind.db") os.makedirs(os.path.dirname(DB_PATH) if os.path.dirname(DB_PATH) else ".", exist_ok=True) @@ -14,19 +16,45 @@ @contextmanager def get_db(): - conn = sqlite3.connect(DB_PATH) - conn.row_factory = sqlite3.Row - conn.execute("PRAGMA journal_mode=WAL") - conn.execute("PRAGMA foreign_keys=ON") + retries = 3 + delay = 0.2 + + conn = None + + for attempt in range(retries): + try: + conn = sqlite3.connect(DB_PATH, timeout=5) + conn.row_factory = sqlite3.Row + conn.execute("PRAGMA journal_mode=WAL") + conn.execute("PRAGMA foreign_keys=ON") + break + + except OperationalError as e: + if "locked" in str(e).lower() and attempt < retries - 1: + time.sleep(delay) + continue + raise + try: yield conn conn.commit() + + except OperationalError as e: + if "locked" in str(e).lower(): + conn.rollback() + raise RuntimeError( + "Database is busy. Please try again in a moment." + ) from e + conn.rollback() + raise + except Exception: conn.rollback() raise - finally: - conn.close() + finally: + if conn: + conn.close() def init_db(): """Create all tables on startup.""" diff --git a/backend/tests/test_db_lock_fallback.py b/backend/tests/test_db_lock_fallback.py new file mode 100644 index 0000000..7e54834 --- /dev/null +++ b/backend/tests/test_db_lock_fallback.py @@ -0,0 +1,8 @@ +from services.db_service import get_db + + +def test_db_connection_opens(): + with get_db() as conn: + result = conn.execute("SELECT 1").fetchone() + + assert result[0] == 1 \ No newline at end of file From 8e5ffd1d84bdaf71acac67c8dd260ae5cf2bf751 Mon Sep 17 00:00:00 2001 From: Aharshi3614 Date: Thu, 11 Jun 2026 15:49:30 +0530 Subject: [PATCH 2/2] feat: add pip and node_modules cache to GitHub Actions CI --- .github/workflows/ci.yml | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e8281bb..01e3636 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,6 +19,14 @@ jobs: with: python-version: "3.11" + - name: Cache pip dependencies + uses: actions/cache@v4 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('backend/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + - name: Install dependencies run: | cd backend @@ -46,8 +54,16 @@ jobs: with: node-version: "20" + - name: Cache node_modules + uses: actions/cache@v4 + with: + path: frontend/node_modules + key: ${{ runner.os }}-node-${{ hashFiles('frontend/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + - name: Install & build run: | cd frontend npm install - npm run build + npm run build \ No newline at end of file