Explorar o código

TG-16: Fix concurrent database locking and UI memory flush on logout

FerRo988 hai 1 mes
pai
achega
0d97ad97c6
Modificáronse 2 ficheiros con 10 adicións e 2 borrados
  1. 4 1
      database.py
  2. 6 1
      static/script.js

+ 4 - 1
database.py

@@ -11,8 +11,11 @@ logger = logging.getLogger(__name__)
 DB_PATH = os.path.join(os.path.dirname(__file__), "localfood.db")
 
 def get_db_connection():
-    conn = sqlite3.connect(DB_PATH)
+    # Enable higher timeout and disable thread checks for FastAPI async compatibility
+    conn = sqlite3.connect(DB_PATH, timeout=20.0, check_same_thread=False)
     conn.row_factory = sqlite3.Row
+    # Enable Write-Ahead Log (WAL) mode for simultaneous read/write operations
+    conn.execute('pragma journal_mode=wal')
     return conn
 
 def create_tables():

+ 6 - 1
static/script.js

@@ -23,7 +23,7 @@ document.addEventListener('DOMContentLoaded', () => {
         if (e.key === 'Enter' && !e.shiftKey) {
             e.preventDefault();
             if (!sendBtn.disabled) {
-                chatForm.dispatchEvent(new Event('submit'));
+                chatForm.requestSubmit();
             }
         }
     });
@@ -248,6 +248,11 @@ document.addEventListener('DOMContentLoaded', () => {
             }
         }
 
+        // Clear chat memory and interface so the next user doesn't see old messages
+        chatHistory = [];
+        chatContainer.innerHTML = '';
+        addMessage('system', 'Hello! I am LocalFoodAI, your completely local nutrition and menu assistant. How can I help you today?');
+
         localStorage.removeItem('localFoodUser');
         localStorage.removeItem('localFoodToken');
         chatApp.style.display = 'none';