perf(issues): replace N+1 queries with batch operations
- Add Repo::find_by_ids() batch query using WHERE id = ANY($1) - Replace 3 sequential validation loops (repos, labels, assignees) with batch queries using ANY($1) - Replace 3 sequential INSERT loops with single INSERT...SELECT FROM unnest() statements - Extract 7 helper methods: validate_issue_repos, validate_issue_labels, validate_issue_assignees, validate_issue_milestone, insert_issue_repo_relations, insert_issue_label_relations, insert_issue_assignees - Reduce issue_create() from ~243 lines to ~80 lines
This commit is contained in:
@@ -39,6 +39,26 @@ impl Repo {
|
||||
.await
|
||||
}
|
||||
|
||||
/// Find multiple non-deleted repos by their IDs in a single query.
|
||||
pub async fn find_by_ids(
|
||||
pool: &PgPool,
|
||||
ids: &[Uuid],
|
||||
) -> Result<Vec<Self>, sqlx::Error> {
|
||||
if ids.is_empty() {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
sqlx::query_as::<_, Repo>(
|
||||
r#"SELECT id, workspace_id, owner_id, name, description, default_branch, visibility,
|
||||
status, is_fork, forked_from_repo_id, storage_node_ids,
|
||||
primary_storage_node_id, storage_path, git_service,
|
||||
archived_at, created_at, updated_at, deleted_at
|
||||
FROM repo WHERE id = ANY($1) AND deleted_at IS NULL"#,
|
||||
)
|
||||
.bind(ids)
|
||||
.fetch_all(pool)
|
||||
.await
|
||||
}
|
||||
|
||||
/// Check if a user is an active member of a repo.
|
||||
pub async fn is_member(
|
||||
pool: &PgPool,
|
||||
|
||||
Reference in New Issue
Block a user