diff options
author | Anthony Wang | 2024-07-27 20:26:00 +0000 |
---|---|---|
committer | Anthony Wang | 2024-07-27 20:26:00 +0000 |
commit | 2cadf76f9da405d8b4ada0121d2f9f7fdc842f6c (patch) | |
tree | 0c4da9f64063f0c0fa2897ad54fab134358404c8 | |
parent | 745a5db246c9dbabaf6c47f05bcdbed31bafe7e3 (diff) |
Disable WAL, ignore modified directories
-rw-r--r-- | server.py | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -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() |