feat(service): expand service layer with new domain operations

- Add IM service modules: audit, channel roles, custom emojis, forum
  tags, integrations, invitations, repo links, slash commands, stages,
  voice, webhooks
- Add PR service modules: review requests, templates
- Add repo service modules: contributors, release assets, git extras
  (archive, branch rename, commit extras, diff/merge, tag, tree)
- Add user service: social (follow/block)
- Add internal auth service
- Update existing service modules with expanded functionality
- Remove deleted IM modules: articles, delivery trace, drafts,
  follows, messages, polls, presence, reactions, threads
This commit is contained in:
zhenyi
2026-06-10 18:49:32 +08:00
parent cec6dce955
commit 420dedbc1e
100 changed files with 3797 additions and 3839 deletions
+42 -4
View File
@@ -95,11 +95,19 @@ impl RepoService {
.map_err(AppError::Database)?;
let now = chrono::Utc::now();
// Try fetching git-derived stats via gRPC (best-effort)
let (commits_count, size_bytes, last_push_at) = self
.try_fetch_git_stats(ctx, wk_name, repo_name)
.await
.unwrap_or((0, 0, None));
let result = sqlx::query_as::<_, RepoStats>(
"UPDATE repo_stats SET stars_count = $1, watchers_count = $2, forks_count = $3, \
branches_count = $4, tags_count = $5, releases_count = $6, \
open_issues_count = $7, open_pull_requests_count = $8, updated_at = $9 \
WHERE repo_id = $10 RETURNING repo_id, stars_count, watchers_count, forks_count, branches_count, tags_count, commits_count, releases_count, open_issues_count, open_pull_requests_count, size_bytes, last_push_at, updated_at",
open_issues_count = $7, open_pull_requests_count = $8, \
commits_count = $9, size_bytes = $10, last_push_at = $11, updated_at = $12 \
WHERE repo_id = $13 RETURNING repo_id, stars_count, watchers_count, forks_count, branches_count, tags_count, commits_count, releases_count, open_issues_count, open_pull_requests_count, size_bytes, last_push_at, updated_at",
)
.bind(stars_count)
.bind(watchers_count)
@@ -109,6 +117,9 @@ impl RepoService {
.bind(releases_count)
.bind(open_issues_count)
.bind(open_prs_count)
.bind(commits_count)
.bind(size_bytes)
.bind(last_push_at)
.bind(now)
.bind(repo_id)
.fetch_one(self.ctx.db.writer())
@@ -118,6 +129,31 @@ impl RepoService {
Ok(result)
}
async fn try_fetch_git_stats(
&self,
ctx: &Session,
wk_name: &str,
repo_name: &str,
) -> Option<(i64, i64, Option<chrono::DateTime<chrono::Utc>>)> {
let commits = self
.git_count_commits(ctx, wk_name, repo_name, None, None, None, None)
.await
.ok()
.map(|r| r.count as i64)
.unwrap_or(0);
let size = self
.git_repo_stats(ctx, wk_name, repo_name)
.await
.ok()
.map(|r| r.size_bytes as i64)
.unwrap_or(0);
let last_push = None; // Not available from current gRPC
Some((commits, size, last_push))
}
async fn ensure_repo_stats(&self, repo_id: Uuid) -> Result<RepoStats, AppError> {
if let Some(stats) = sqlx::query_as::<_, RepoStats>(
"SELECT repo_id, stars_count, watchers_count, forks_count, branches_count, tags_count, commits_count, releases_count, open_issues_count, open_pull_requests_count, size_bytes, last_push_at, updated_at FROM repo_stats WHERE repo_id = $1",
@@ -141,12 +177,14 @@ impl RepoService {
.execute(self.ctx.db.writer())
.await
.map_err(AppError::Database)?;
// Read from writer to avoid replication lag
sqlx::query_as::<_, RepoStats>(
"SELECT repo_id, stars_count, watchers_count, forks_count, branches_count, tags_count, commits_count, releases_count, open_issues_count, open_pull_requests_count, size_bytes, last_push_at, updated_at FROM repo_stats WHERE repo_id = $1",
)
.bind(repo_id)
.fetch_one(self.ctx.db.reader())
.fetch_optional(self.ctx.db.writer())
.await
.map_err(AppError::Database)
.map_err(AppError::Database)?
.ok_or(AppError::NotFound("repo stats not found".into()))
}
}