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:
zhenyi
2026-06-10 18:49:00 +08:00
parent 61dc08c036
commit 15b875e18d
2 changed files with 258 additions and 141 deletions
+20
View File
@@ -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,