Do not attempt to reindex a file if previous attempts have failed.

Add doc comment to JobHandle

Co-authored-by: Kyle <kyle@zed.dev>
This commit is contained in:
Piotr Osiewicz 2023-08-21 13:23:11 +02:00
parent 1a88444f2f
commit 61041b0cd1

View File

@ -98,6 +98,8 @@ struct ProjectState {
#[derive(Clone)]
struct JobHandle {
/// The outer Arc is here to count the clones of a JobHandle instance;
/// when the last handle to a given job is dropped, we decrement a counter (just once).
tx: Arc<Weak<Mutex<watch::Sender<usize>>>>,
}
@ -389,6 +391,20 @@ impl SemanticIndex {
.await
.unwrap();
}
} else {
// Insert the file in spite of failure so that future attempts to index it do not take place (unless the file is changed).
for (worktree_id, documents, path, mtime, job_handle) in embeddings_queue.into_iter() {
db_update_tx
.send(DbOperation::InsertFile {
worktree_id,
documents: vec![],
path,
mtime,
job_handle,
})
.await
.unwrap();
}
}
}
@ -848,6 +864,7 @@ impl Entity for SemanticIndex {
impl Drop for JobHandle {
fn drop(&mut self) {
if let Some(inner) = Arc::get_mut(&mut self.tx) {
// This is the last instance of the JobHandle (regardless of it's origin - whether it was cloned or not)
if let Some(tx) = inner.upgrade() {
let mut tx = tx.lock();
*tx.borrow_mut() -= 1;