From 2cadf76f9da405d8b4ada0121d2f9f7fdc842f6c Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 27 Jul 2024 20:26:00 +0000 Subject: Disable WAL, ignore modified directories --- server.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/server.py b/server.py index 2636375..7d33a66 100644 --- a/server.py +++ b/server.py @@ -14,9 +14,7 @@ import model print("Connecting to DB") -# Possible corruption? con = sqlite3.connect("index.db", check_same_thread=False) -con.execute("PRAGMA journal_mode=wal") con.enable_load_extension(True) sqlite_vec.load(con) cur = con.cursor() @@ -27,7 +25,6 @@ cur.execute( "CREATE VIRTUAL TABLE IF NOT EXISTS emb USING vec0(id INTEGER PRIMARY KEY, embedding float[1024] distance_metric=cosine)" ) con.commit() -lock = threading.Lock() def get_parent(path): @@ -37,17 +34,20 @@ def get_parent(path): class EventHandler(FileSystemEventHandler): + lock = threading.Lock() + def dispatch(self, event): - lock.acquire() + self.lock.acquire() print(event) super().dispatch(event) - lock.release() + self.lock.release() def on_created(self, event): index(event.src_path, get_parent(event.src_path)) def on_modified(self, event): - self.on_created(event) + if not event.is_directory: + self.on_created(event) def on_deleted(self, event): res = cur.execute("SELECT id FROM idx WHERE path = ?", (event.src_path,)) @@ -186,4 +186,3 @@ print("Starting RPC server") server = SimpleXMLRPCServer(("localhost", int(os.environ.get("PORT", 8000)))) server.register_function(search) server.serve_forever() -con.close() -- cgit v1.2.3-70-g09d2