From 9ef90acf199bf99601ec1fa5a1cb95c3796a5863 Mon Sep 17 00:00:00 2001 From: Luisa Vasquez Gomez Date: Fri, 15 Nov 2024 04:23:01 -0800 Subject: [PATCH] monad: show public and draft count Summary: Same statement as previous diff Differential Revision: D65877388 fbshipit-source-id: 9c6eddcd8d91c60f58c9adf0ce9118d96e194d48 --- .../phases/sqlphases/src/sql_phases.rs | 4 +++ .../phases/sqlphases/src/sql_store.rs | 21 ++++++++++++++ eden/mononoke/phases/src/lib.rs | 4 +++ .../tools/admin/src/commands/repo_info.rs | 29 +++++++++++++++---- 4 files changed, 52 insertions(+), 6 deletions(-) diff --git a/eden/mononoke/phases/sqlphases/src/sql_phases.rs b/eden/mononoke/phases/sqlphases/src/sql_phases.rs index 090b226c6950d..4f6af38e0a884 100644 --- a/eden/mononoke/phases/sqlphases/src/sql_phases.rs +++ b/eden/mononoke/phases/sqlphases/src/sql_phases.rs @@ -265,6 +265,10 @@ impl Phases for SqlPhases { repo_id: self.repo_id, }) } + + async fn count_all_public(&self, ctx: &CoreContext, id: RepositoryId) -> Result { + self.phases_store.count_all_public(ctx, id).await + } } /// Mark all commits reachable from `public_heads` as public diff --git a/eden/mononoke/phases/sqlphases/src/sql_store.rs b/eden/mononoke/phases/sqlphases/src/sql_store.rs index 8fabc3add8c0c..0c56c11a5eccf 100644 --- a/eden/mononoke/phases/sqlphases/src/sql_store.rs +++ b/eden/mononoke/phases/sqlphases/src/sql_store.rs @@ -173,6 +173,20 @@ impl SqlPhasesStore { .await?; Ok(ans.into_iter().map(|x| x.0).collect()) } + + pub async fn count_all_public( + &self, + ctx: &CoreContext, + repo_id: RepositoryId, + ) -> Result { + let ans = CountAllPublic::maybe_traced_query( + &self.read_connection, + ctx.client_request_info(), + &repo_id, + ) + .await?; + Ok(ans.first().map_or(0, |(count,)| *count)) + } } impl MemcacheEntity for SqlPhase { @@ -295,4 +309,11 @@ mononoke_queries! { AND phase like 'Public'" ) } + + read CountAllPublic(repo_id: RepositoryId) -> (u64 ) { + "SELECT count(*) + FROM phases + WHERE repo_id = {repo_id} + AND phase = 'Public'" + } } diff --git a/eden/mononoke/phases/src/lib.rs b/eden/mononoke/phases/src/lib.rs index b39950cd9194e..83239f4a7c453 100644 --- a/eden/mononoke/phases/src/lib.rs +++ b/eden/mononoke/phases/src/lib.rs @@ -16,6 +16,7 @@ use async_trait::async_trait; use context::CoreContext; pub use errors::PhasesError; use mononoke_types::ChangesetId; +use mononoke_types::RepositoryId; #[derive(Abomonation, Clone, Copy, PartialEq, Eq, Debug)] pub enum Phase { @@ -103,6 +104,9 @@ pub trait Phases: Send + Sync { /// Return a copy of this phases object with the set of public /// heads frozen. fn with_frozen_public_heads(&self, heads: Vec) -> ArcPhases; + + /// Return a the count of all public commits. + async fn count_all_public(&self, ctx: &CoreContext, id: RepositoryId) -> Result; } #[cfg(test)] diff --git a/eden/mononoke/tools/admin/src/commands/repo_info.rs b/eden/mononoke/tools/admin/src/commands/repo_info.rs index 1d6b91262f9f6..15c876b5d2f35 100644 --- a/eden/mononoke/tools/admin/src/commands/repo_info.rs +++ b/eden/mononoke/tools/admin/src/commands/repo_info.rs @@ -13,6 +13,8 @@ use bookmarks::BookmarksRef; use clap::Parser; use mononoke_app::args::RepoArgs; use mononoke_app::MononokeApp; +use phases::Phases; +use phases::PhasesRef; use repo_identity::RepoIdentity; use repo_identity::RepoIdentityRef; use sql_commit_graph_storage::CommitGraphBulkFetcher; @@ -23,6 +25,9 @@ use sql_commit_graph_storage::CommitGraphBulkFetcherRef; pub struct CommandArgs { #[clap(flatten)] repo: RepoArgs, + /// Show total, public and draft commit counts (this can be expensive for large repos) + #[clap(long)] + show_commit_count: bool, } #[derive(Clone)] @@ -36,6 +41,9 @@ pub struct Repo { #[facet] commit_graph_bulk_fetcher: CommitGraphBulkFetcher, + + #[facet] + phases: dyn Phases, } pub async fn run(app: MononokeApp, args: CommandArgs) -> Result<()> { @@ -45,7 +53,7 @@ pub async fn run(app: MononokeApp, args: CommandArgs) -> Result<()> { .open_repo(&args.repo) .await .context("Failed to open repo")?; - + let id = repo.repo_identity().id(); println!("Repo: {}", repo.repo_identity().name()); println!("Repo-Id: {}", repo.repo_identity().id()); let main_bookmark = BookmarkKey::new("master")?; @@ -61,12 +69,21 @@ pub async fn run(app: MononokeApp, args: CommandArgs) -> Result<()> { main_bookmark, main_bookmark_value.as_deref().unwrap_or("(not set)") ); + if args.show_commit_count { + let commits = repo + .commit_graph_bulk_fetcher() + .fetch_commit_count(&ctx, id) + .await?; + + let public = repo.phases().count_all_public(&ctx, id).await?; - let commits = repo - .commit_graph_bulk_fetcher() - .fetch_commit_count(&ctx, repo.repo_identity().id()) - .await?; + println!( + "Commits: {} (Public: {}, Draft: {})", + commits, + public, + commits - public + ); + } - println!("Commits: {}", commits); Ok(()) }