aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2024-07-27 20:26:00 +0000
committerAnthony Wang2024-07-27 20:26:00 +0000
commit2cadf76f9da405d8b4ada0121d2f9f7fdc842f6c (patch)
tree0c4da9f64063f0c0fa2897ad54fab134358404c8
parent745a5db246c9dbabaf6c47f05bcdbed31bafe7e3 (diff)
Disable WAL, ignore modified directories
-rw-r--r--server.py13
1 files 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()