Eagerly index project on workspace creation if it was indexed before
Co-Authored-By: Kyle Caverly <kyle@zed.dev>
This commit is contained in:
parent
3b784668c0
commit
65e17e212d
3 changed files with 33 additions and 8 deletions
|
@ -867,7 +867,7 @@ impl ProjectSearchView {
|
||||||
SemanticIndex::global(cx)
|
SemanticIndex::global(cx)
|
||||||
.map(|semantic| {
|
.map(|semantic| {
|
||||||
let project = self.model.read(cx).project.clone();
|
let project = self.model.read(cx).project.clone();
|
||||||
semantic.update(cx, |this, cx| this.project_previously_indexed(project, cx))
|
semantic.update(cx, |this, cx| this.project_previously_indexed(&project, cx))
|
||||||
})
|
})
|
||||||
.unwrap_or(Task::ready(Ok(false)))
|
.unwrap_or(Task::ready(Ok(false)))
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ use std::{
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
rc::Rc,
|
rc::Rc,
|
||||||
sync::Arc,
|
sync::Arc,
|
||||||
time::{Instant, SystemTime},
|
time::SystemTime,
|
||||||
};
|
};
|
||||||
use util::TryFutureExt;
|
use util::TryFutureExt;
|
||||||
|
|
||||||
|
@ -232,7 +232,6 @@ impl VectorDatabase {
|
||||||
|
|
||||||
let file_id = db.last_insert_rowid();
|
let file_id = db.last_insert_rowid();
|
||||||
|
|
||||||
let t0 = Instant::now();
|
|
||||||
let mut query = db.prepare(
|
let mut query = db.prepare(
|
||||||
"
|
"
|
||||||
INSERT INTO spans
|
INSERT INTO spans
|
||||||
|
@ -240,10 +239,6 @@ impl VectorDatabase {
|
||||||
VALUES (?1, ?2, ?3, ?4, ?5, ?6)
|
VALUES (?1, ?2, ?3, ?4, ?5, ?6)
|
||||||
",
|
",
|
||||||
)?;
|
)?;
|
||||||
log::trace!(
|
|
||||||
"Preparing Query Took: {:?} milliseconds",
|
|
||||||
t0.elapsed().as_millis()
|
|
||||||
);
|
|
||||||
|
|
||||||
for span in spans {
|
for span in spans {
|
||||||
query.execute(params![
|
query.execute(params![
|
||||||
|
|
|
@ -35,6 +35,7 @@ use util::{
|
||||||
paths::EMBEDDINGS_DIR,
|
paths::EMBEDDINGS_DIR,
|
||||||
ResultExt,
|
ResultExt,
|
||||||
};
|
};
|
||||||
|
use workspace::WorkspaceCreated;
|
||||||
|
|
||||||
const SEMANTIC_INDEX_VERSION: usize = 10;
|
const SEMANTIC_INDEX_VERSION: usize = 10;
|
||||||
const BACKGROUND_INDEXING_DELAY: Duration = Duration::from_secs(5 * 60);
|
const BACKGROUND_INDEXING_DELAY: Duration = Duration::from_secs(5 * 60);
|
||||||
|
@ -57,6 +58,35 @@ pub fn init(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cx.subscribe_global::<WorkspaceCreated, _>({
|
||||||
|
move |event, cx| {
|
||||||
|
let Some(semantic_index) = SemanticIndex::global(cx) else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
let workspace = &event.0;
|
||||||
|
if let Some(workspace) = workspace.upgrade(cx) {
|
||||||
|
let project = workspace.read(cx).project().clone();
|
||||||
|
if project.read(cx).is_local() {
|
||||||
|
cx.spawn(|mut cx| async move {
|
||||||
|
let previously_indexed = semantic_index
|
||||||
|
.update(&mut cx, |index, cx| {
|
||||||
|
index.project_previously_indexed(&project, cx)
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
|
if previously_indexed {
|
||||||
|
semantic_index
|
||||||
|
.update(&mut cx, |index, cx| index.index_project(project, cx))
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
anyhow::Ok(())
|
||||||
|
})
|
||||||
|
.detach_and_log_err(cx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.detach();
|
||||||
|
|
||||||
cx.spawn(move |mut cx| async move {
|
cx.spawn(move |mut cx| async move {
|
||||||
let semantic_index = SemanticIndex::new(
|
let semantic_index = SemanticIndex::new(
|
||||||
fs,
|
fs,
|
||||||
|
@ -356,7 +386,7 @@ impl SemanticIndex {
|
||||||
|
|
||||||
pub fn project_previously_indexed(
|
pub fn project_previously_indexed(
|
||||||
&mut self,
|
&mut self,
|
||||||
project: ModelHandle<Project>,
|
project: &ModelHandle<Project>,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<bool>> {
|
) -> Task<Result<bool>> {
|
||||||
let worktrees_indexed_previously = project
|
let worktrees_indexed_previously = project
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue