semantic_index: Disable embeddings index for non-staff (#19618)

This PR disables the embeddings index for non-staff users.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-10-23 12:34:51 -04:00 committed by GitHub
parent c3860804ff
commit 69b12f4e33
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 17 additions and 0 deletions

View file

@ -5,6 +5,7 @@ use crate::{
};
use anyhow::{anyhow, Context as _, Result};
use collections::Bound;
use feature_flags::FeatureFlagAppExt;
use fs::Fs;
use futures::stream::StreamExt;
use futures_batch::ChunksTimeoutStreamExt;
@ -15,6 +16,7 @@ use log;
use project::{Entry, UpdatedEntriesSet, Worktree};
use serde::{Deserialize, Serialize};
use smol::channel;
use smol::future::FutureExt;
use std::{
cmp::Ordering,
future::Future,
@ -65,6 +67,10 @@ impl EmbeddingIndex {
&self,
cx: &AppContext,
) -> impl Future<Output = Result<()>> {
if !cx.is_staff() {
return async move { Ok(()) }.boxed();
}
let worktree = self.worktree.read(cx).snapshot();
let worktree_abs_path = worktree.abs_path().clone();
let scan = self.scan_entries(worktree, cx);
@ -75,6 +81,7 @@ impl EmbeddingIndex {
futures::try_join!(scan.task, chunk.task, embed.task, persist)?;
Ok(())
}
.boxed()
}
pub fn index_updated_entries(
@ -82,6 +89,10 @@ impl EmbeddingIndex {
updated_entries: UpdatedEntriesSet,
cx: &AppContext,
) -> impl Future<Output = Result<()>> {
if !cx.is_staff() {
return async move { Ok(()) }.boxed();
}
let worktree = self.worktree.read(cx).snapshot();
let worktree_abs_path = worktree.abs_path().clone();
let scan = self.scan_updated_entries(worktree, updated_entries.clone(), cx);
@ -92,6 +103,7 @@ impl EmbeddingIndex {
futures::try_join!(scan.task, chunk.task, embed.task, persist)?;
Ok(())
}
.boxed()
}
fn scan_entries(&self, worktree: Snapshot, cx: &AppContext) -> ScanEntries {

View file

@ -336,6 +336,11 @@ mod tests {
init_test(cx);
cx.update(|cx| {
// This functionality is staff-flagged.
cx.update_flags(true, vec![]);
});
let temp_dir = tempfile::tempdir().unwrap();
let mut semantic_index = SemanticDb::new(