Skip to content

Commit

Permalink
Revert "Oss fixes (#1275)" (#1276)
Browse files Browse the repository at this point in the history
This reverts commit 17bcca6.
  • Loading branch information
anastasiya1155 committed Jun 12, 2024
1 parent 17bcca6 commit 8c24fef
Show file tree
Hide file tree
Showing 19 changed files with 102 additions and 51 deletions.
17 changes: 14 additions & 3 deletions server/bleep/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ impl Agent {
query: &str,
) -> impl Iterator<Item = FileDocument> + 'a {
let langs = self.last_exchange().query.langs.iter().map(Deref::deref);
let user_id = "1";
let user_id = self.user.username().expect("didn't have user ID");

let (repos, branches): (Vec<_>, Vec<_>) = sqlx::query! {
"SELECT pr.repo_ref, pr.branch
Expand Down Expand Up @@ -441,12 +441,23 @@ impl Agent {
fn store(&mut self) -> impl Future<Output = ()> {
let sql = Arc::clone(&self.app.sql);

let user_id = "1".to_string();
let user_id = self
.user
.username()
.context("didn't have user ID")
.map(str::to_owned);

let conversation = self.conversation.clone();

async move {
conversation.store(&sql, &user_id).await.expect("failed to store conversation");
let result = match user_id {
Ok(user_id) => conversation.store(&sql, &user_id).await,
Err(e) => Err(e),
};

if let Err(e) = result {
error!("failed to store conversation: {e}");
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/bleep/src/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl BackgroundExecutor {
let tokio_ref = tokio_ref.clone();
let thread_priority = thread_priority::ThreadPriority::Max;

thread::Builder::new()
std::thread::Builder::new()
.name("index-worker".to_owned())
.spawn_with_priority(thread_priority, move |_| {
let _tokio = tokio_ref.enter();
Expand Down
4 changes: 2 additions & 2 deletions server/bleep/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ impl<'a> ChunkCache<'a> {
let branches_hash = blake3::hash(payload.branches.join("\n").as_ref()).to_string();

match self.cache.entry(id) {
Entry::Occupied(mut existing) => {
scc::hash_map::Entry::Occupied(mut existing) => {
let key = existing.key();
trace!(?key, "found; not upserting new");
if existing.get().value != branches_hash {
Expand All @@ -560,7 +560,7 @@ impl<'a> ChunkCache<'a> {
}
*existing.get_mut() = branches_hash.into();
}
Entry::Vacant(vacant) => {
scc::hash_map::Entry::Vacant(vacant) => {
let key = vacant.key();
trace!(?key, "inserting new");
self.new_sql
Expand Down
2 changes: 1 addition & 1 deletion server/bleep/src/commits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ Assistant: initialisation"#,

pub async fn generate_tutorial_questions(
db: crate::db::SqlDb,
llm_gateway: Result<llm::client::Client>,
llm_gateway: Result<crate::llm::client::Client>,
repo_pool: RepositoryPool,
reporef: RepoRef,
) -> Result<()> {
Expand Down
4 changes: 2 additions & 2 deletions server/bleep/src/indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ impl Indexes {
// we don't support old schemas, and tantivy will hard
// error if we try to open a db with a different schema.
if config.index_path("repo").as_ref().exists() {
fs::remove_dir_all(config.index_path("repo"))?;
std::fs::remove_dir_all(config.index_path("repo"))?;
debug!("removed index repo dir")
}
if config.index_path("content").as_ref().exists() {
fs::remove_dir_all(config.index_path("content"))?;
std::fs::remove_dir_all(config.index_path("content"))?;
debug!("removed index content dir")
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion server/bleep/src/indexes/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub struct File {

impl File {
pub fn new() -> Self {
let mut builder = SchemaBuilder::new();
let mut builder = tantivy::schema::SchemaBuilder::new();
let trigram = TextOptions::default().set_stored().set_indexing_options(
TextFieldIndexing::default()
.set_tokenizer("default")
Expand Down
2 changes: 1 addition & 1 deletion server/bleep/src/query/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ impl<'a> Literal<'a> {

/// Force this literal into the `Regex` variant.
fn make_regex(&mut self) {
*self = match mem::take(self) {
*self = match std::mem::take(self) {
Self::Plain(s) | Self::Regex(s) => Self::Regex(s),
}
}
Expand Down
2 changes: 1 addition & 1 deletion server/bleep/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl FromStr for RepoRef {
}

impl Display for RepoRef {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self.backend() {
Backend::Github => write!(f, "github.com/{}", self.name()),
Backend::Local => write!(f, "local/{}", self.name()),
Expand Down
10 changes: 7 additions & 3 deletions server/bleep/src/webserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ impl Error {
self
}

fn internal<S: fmt::Display>(message: S) -> Self {
fn internal<S: std::fmt::Display>(message: S) -> Self {
Error {
status: StatusCode::INTERNAL_SERVER_ERROR,
body: EndpointError {
Expand All @@ -264,7 +264,7 @@ impl Error {
}
}

fn user<S: fmt::Display>(message: S) -> Self {
fn user<S: std::fmt::Display>(message: S) -> Self {
Error {
status: StatusCode::BAD_REQUEST,
body: EndpointError {
Expand All @@ -274,7 +274,7 @@ impl Error {
}
}

fn not_found<S: fmt::Display>(message: S) -> Self {
fn not_found<S: std::fmt::Display>(message: S) -> Self {
Error {
status: StatusCode::NOT_FOUND,
body: EndpointError {
Expand Down Expand Up @@ -360,3 +360,7 @@ async fn health(State(app): State<Application>) {
// subsystem checks at this stage
app.semantic.health_check().await.unwrap()
}

fn no_user_id() -> Error {
Error::user("didn't have user ID")
}
4 changes: 2 additions & 2 deletions server/bleep/src/webserver/answer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub(super) async fn answer(
info!(?params.q, "handling /answer query");
let query_id = uuid::Uuid::new_v4();

let user_id = "1";
let user_id = user.username().ok_or_else(super::no_user_id)?;

let mut conversation = match params.conversation_id {
Some(conversation_id) => {
Expand Down Expand Up @@ -173,7 +173,7 @@ impl AgentExecutor {
async fn try_execute(&mut self) -> super::Result<SseDynStream<Result<sse::Event>>> {
QueryLog::new(&self.app.sql).insert(&self.params.q).await?;

let username = "1";
let username = self.user.username().ok_or_else(super::no_user_id)?;

let repo_refs = sqlx::query! {
"SELECT repo_ref
Expand Down
2 changes: 1 addition & 1 deletion server/bleep/src/webserver/conversation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ pub(in crate::webserver) async fn get(
Path((project_id, conversation_id)): Path<(i64, i64)>,
State(app): State<Application>,
) -> webserver::Result<Json<Conversation>> {
let user_id = "1";
let user_id = user.username().ok_or_else(super::no_user_id)?;

let mut conversation =
Conversation::load(&app.sql, user_id, project_id, conversation_id).await?;
Expand Down
10 changes: 5 additions & 5 deletions server/bleep/src/webserver/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub async fn list(
app: Extension<Application>,
user: Extension<User>,
) -> webserver::Result<Json<Vec<ListItem>>> {
let user_id = "1".to_string();
let user_id = user.username().ok_or_else(super::no_user_id)?.to_string();

let projects = sqlx::query! {
"SELECT p.id, p.name, (
Expand Down Expand Up @@ -91,7 +91,7 @@ pub async fn create(
user: Extension<User>,
Json(params): Json<Create>,
) -> webserver::Result<String> {
let user_id = "1".to_string();
let user_id = user.username().ok_or_else(super::no_user_id)?.to_string();

let project_id = sqlx::query! {
"INSERT INTO projects (user_id, name) VALUES (?, ?) RETURNING id",
Expand All @@ -118,7 +118,7 @@ pub async fn get(
user: Extension<User>,
Path(id): Path<i64>,
) -> webserver::Result<Json<Get>> {
let user_id = "1".to_string();
let user_id = user.username().ok_or_else(super::no_user_id)?.to_string();

let row = sqlx::query! {
"SELECT name, (
Expand Down Expand Up @@ -172,7 +172,7 @@ pub async fn update(
Path(id): Path<i64>,
Json(update): Json<Update>,
) -> webserver::Result<()> {
let user_id = "1".to_string();
let user_id = user.username().ok_or_else(super::no_user_id)?.to_string();

sqlx::query! {
"UPDATE projects SET name = ? WHERE id = ? AND user_id = ? RETURNING id",
Expand All @@ -191,7 +191,7 @@ pub async fn delete(
user: Extension<User>,
Path(id): Path<i64>,
) -> webserver::Result<()> {
let user_id = "1".to_string();
let user_id = user.username().ok_or_else(super::no_user_id)?;

sqlx::query! {
"DELETE FROM projects WHERE id = ? AND user_id = ? RETURNING id",
Expand Down
15 changes: 12 additions & 3 deletions server/bleep/src/webserver/project/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ pub async fn list(
user: Extension<User>,
Path(project_id): Path<i64>,
) -> webserver::Result<Json<Vec<Doc>>> {
let user_id = "1".to_string();
let user_id = user
.username()
.ok_or_else(webserver::no_user_id)?
.to_string();

let docs = sqlx::query_as! {
Doc,
Expand Down Expand Up @@ -54,7 +57,10 @@ pub async fn add(
Path(project_id): Path<i64>,
Json(params): Json<Add>,
) -> webserver::Result<()> {
let user_id = "1".to_string();
let user_id = user
.username()
.ok_or_else(webserver::no_user_id)?
.to_string();

sqlx::query! {
"SELECT id FROM projects WHERE id = ? AND user_id = ?",
Expand All @@ -81,7 +87,10 @@ pub async fn delete(
user: Extension<User>,
Path((project_id, doc_id)): Path<(i64, i64)>,
) -> webserver::Result<()> {
let user_id = "1".to_string();
let user_id = user
.username()
.ok_or_else(webserver::no_user_id)?
.to_string();

sqlx::query! {
"DELETE FROM project_docs
Expand Down
20 changes: 16 additions & 4 deletions server/bleep/src/webserver/project/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ pub async fn list(
user: Extension<User>,
Path(project_id): Path<i64>,
) -> webserver::Result<Json<Vec<ListItem>>> {
let user_id = "1".to_string();
let user_id = user
.username()
.ok_or_else(webserver::no_user_id)?
.to_string();

let list = sqlx::query! {
"SELECT repo_ref, branch
Expand Down Expand Up @@ -65,7 +68,10 @@ pub async fn add(
Path(project_id): Path<i64>,
Json(params): Json<Add>,
) -> webserver::Result<()> {
let user_id = "1".to_string();
let user_id = user
.username()
.ok_or_else(webserver::no_user_id)?
.to_string();

sqlx::query! {
"SELECT id FROM projects WHERE id = ? AND user_id = ?",
Expand Down Expand Up @@ -102,7 +108,10 @@ pub async fn delete(
Path(project_id): Path<i64>,
Query(Delete { repo_ref }): Query<Delete>,
) -> webserver::Result<()> {
let user_id = "1".to_string();
let user_id = user
.username()
.ok_or_else(webserver::no_user_id)?
.to_string();

sqlx::query! {
"DELETE FROM project_repos
Expand Down Expand Up @@ -135,7 +144,10 @@ pub async fn put(
Path(project_id): Path<i64>,
Json(params): Json<Put>,
) -> webserver::Result<()> {
let user_id = "1".to_string();
let user_id = user
.username()
.ok_or_else(webserver::no_user_id)?
.to_string();

sqlx::query! {
"SELECT id FROM projects WHERE id = ? AND user_id = ?",
Expand Down
2 changes: 1 addition & 1 deletion server/bleep/src/webserver/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ pub(super) async fn handle(
.query(&app)
.await
.map(json)
.map_err(Error::from)
.map_err(super::Error::from)
}
2 changes: 1 addition & 1 deletion server/bleep/src/webserver/repos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl Repo {
last_update: origin.pushed_at.unwrap(),
last_index: None,
most_common_lang: None,
branch_filter: BranchFilterConfig::Select(vec![]),
branch_filter: crate::repo::BranchFilterConfig::Select(vec![]),
file_filter: Default::default(),
branches: vec![],
}
Expand Down
2 changes: 1 addition & 1 deletion server/bleep/src/webserver/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub(super) async fn semantic_code(
Ok(q) => semantic::execute::execute(semantic, q, args)
.await
.map(json)
.map_err(Error::from),
.map_err(super::Error::from),
Err(err) => {
error!(?err, "Couldn't parse query");
Err(Error::new(ErrorKind::UpstreamService, "error"))
Expand Down
Loading

0 comments on commit 8c24fef

Please sign in to comment.