Skip to content

Commit

Permalink
monad: show public and draft count
Browse files Browse the repository at this point in the history
Summary: Same statement as previous diff

Differential Revision: D65877388

fbshipit-source-id: 9c6eddcd8d91c60f58c9adf0ce9118d96e194d48
  • Loading branch information
lmvasquezg authored and facebook-github-bot committed Nov 15, 2024
1 parent 51f07ed commit 9ef90ac
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
4 changes: 4 additions & 0 deletions eden/mononoke/phases/sqlphases/src/sql_phases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ impl Phases for SqlPhases {
repo_id: self.repo_id,
})
}

async fn count_all_public(&self, ctx: &CoreContext, id: RepositoryId) -> Result<u64, Error> {
self.phases_store.count_all_public(ctx, id).await
}
}

/// Mark all commits reachable from `public_heads` as public
Expand Down
21 changes: 21 additions & 0 deletions eden/mononoke/phases/sqlphases/src/sql_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64, Error> {
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 {
Expand Down Expand Up @@ -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'"
}
}
4 changes: 4 additions & 0 deletions eden/mononoke/phases/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<ChangesetId>) -> ArcPhases;

/// Return a the count of all public commits.
async fn count_all_public(&self, ctx: &CoreContext, id: RepositoryId) -> Result<u64>;
}

#[cfg(test)]
Expand Down
29 changes: 23 additions & 6 deletions eden/mononoke/tools/admin/src/commands/repo_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)]
Expand All @@ -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<()> {
Expand All @@ -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")?;
Expand All @@ -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(())
}

0 comments on commit 9ef90ac

Please sign in to comment.