Skip to content

Commit

Permalink
fix(scheduler): when index is recreated, the cache should be cleared (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
wsxiaoys authored May 26, 2024
1 parent 1d1edfe commit f9c4240
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions crates/tabby-scheduler/src/code/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 3 additions & 1 deletion crates/tabby-scheduler/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ pub trait IndexAttributeBuilder<T>: Send + Sync {
pub struct Indexer<T> {
builder: Box<dyn IndexAttributeBuilder<T>>,
writer: IndexWriter,
pub recreated: bool,
}

impl<T> Indexer<T> {
pub fn new(builder: impl IndexAttributeBuilder<T> + '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");

Self {
builder: Box::new(builder),
writer,
recreated,
}
}

Expand Down

0 comments on commit f9c4240

Please sign in to comment.