From f9c42407cb7aa32cef3b09fc82b6c43f345bba19 Mon Sep 17 00:00:00 2001 From: Meng Zhang Date: Sun, 26 May 2024 11:55:03 +0800 Subject: [PATCH] fix(scheduler): when index is recreated, the cache should be cleared (#2241) --- crates/tabby-scheduler/src/code/index.rs | 3 +++ crates/tabby-scheduler/src/indexer.rs | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/tabby-scheduler/src/code/index.rs b/crates/tabby-scheduler/src/code/index.rs index 8e4bb840eb0a..089ea522b167 100644 --- a/crates/tabby-scheduler/src/code/index.rs +++ b/crates/tabby-scheduler/src/code/index.rs @@ -12,6 +12,9 @@ static AVG_LINE_LENGTH_THRESHOLD: f32 = 150f32; pub async fn index_repository(cache: &mut CacheStore, repository: &RepositoryConfig) { let index = create_code_index(); + if index.recreated { + cache.clear_indexed() + } add_changed_documents(cache, repository, &index).await; index.commit(); } diff --git a/crates/tabby-scheduler/src/indexer.rs b/crates/tabby-scheduler/src/indexer.rs index 42233dee9c74..7c1d565ded18 100644 --- a/crates/tabby-scheduler/src/indexer.rs +++ b/crates/tabby-scheduler/src/indexer.rs @@ -18,12 +18,13 @@ pub trait IndexAttributeBuilder: Send + Sync { pub struct Indexer { builder: Box>, writer: IndexWriter, + pub recreated: bool, } impl Indexer { pub fn new(builder: impl IndexAttributeBuilder + 'static) -> Self { let doc = IndexSchema::instance(); - let (_, index) = open_or_create_index(&doc.schema, &path::index_dir()); + let (recreated, index) = open_or_create_index(&doc.schema, &path::index_dir()); let writer = index .writer(150_000_000) .expect("Failed to create index writer"); @@ -31,6 +32,7 @@ impl Indexer { Self { builder: Box::new(builder), writer, + recreated, } }