diff --git a/ee/tabby-db/migrations/0021_repository-name-index.down.sql b/ee/tabby-db/migrations/0021_repository-name-index.down.sql new file mode 100644 index 000000000000..5a8a6d00e732 --- /dev/null +++ b/ee/tabby-db/migrations/0021_repository-name-index.down.sql @@ -0,0 +1 @@ +DROP INDEX idx_repository_name; diff --git a/ee/tabby-db/migrations/0021_repository-name-index.up.sql b/ee/tabby-db/migrations/0021_repository-name-index.up.sql new file mode 100644 index 000000000000..0da0a538a399 --- /dev/null +++ b/ee/tabby-db/migrations/0021_repository-name-index.up.sql @@ -0,0 +1 @@ +-- Add up migration script here diff --git a/ee/tabby-db/schema.sqlite b/ee/tabby-db/schema.sqlite index 451323a8b093..1032589a279b 100644 Binary files a/ee/tabby-db/schema.sqlite and b/ee/tabby-db/schema.sqlite differ diff --git a/ee/tabby-db/src/repositories.rs b/ee/tabby-db/src/repositories.rs index b629b0fa1002..599fc41a82bd 100644 --- a/ee/tabby-db/src/repositories.rs +++ b/ee/tabby-db/src/repositories.rs @@ -1,5 +1,5 @@ use anyhow::{anyhow, Result}; -use sqlx::{prelude::FromRow, query, query_scalar}; +use sqlx::{prelude::FromRow, query}; use crate::{make_pagination_query, DbConn, SQLXResultExt}; @@ -65,11 +65,13 @@ impl DbConn { } } - pub async fn get_repository_git_url(&self, name: String) -> Result { - let url = query_scalar!("SELECT git_url FROM repositories WHERE name = ?", name) - .fetch_one(&self.pool) - .await?; - Ok(url) + pub async fn get_repository_by_name(&self, name: String) -> Result { + let repository = + sqlx::query_as("SELECT id, name, git_url FROM repositories WHERE name = ?;") + .bind(name) + .fetch_one(&self.pool) + .await?; + Ok(repository) } } @@ -107,7 +109,10 @@ mod tests { assert_eq!(repository.git_url, "testurl2"); assert_eq!(repository.name, "test2"); assert_eq!( - conn.get_repository_git_url("test2".into()).await.unwrap(), + conn.get_repository_by_name("test2".into()) + .await + .unwrap() + .git_url, repository.git_url ); } diff --git a/ee/tabby-webserver/src/service/repository.rs b/ee/tabby-webserver/src/service/repository.rs index 28b3aaf570ab..dea4d1aa3d98 100644 --- a/ee/tabby-webserver/src/service/repository.rs +++ b/ee/tabby-webserver/src/service/repository.rs @@ -96,7 +96,7 @@ impl RepositoryService for DbConn { if path_glob.trim().is_empty() { return Ok(vec![]); } - let git_url = self.get_repository_git_url(name.clone()).await?; + let git_url = self.get_repository_by_name(name.clone()).await?.git_url; let config = RepositoryConfig::new_named(name, git_url); let matching = find_glob(&config.dir(), &path_glob, top_n) .await