Skip to content

Commit

Permalink
feat: clean-up unused orgs
Browse files Browse the repository at this point in the history
  • Loading branch information
akorchyn committed Nov 5, 2024
1 parent 5ff3119 commit fd3ed5d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/src/contract_pull.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ async fn fetch_and_store_repos(
) -> anyhow::Result<()> {
let organizations = near_client.repos().await?;
DB::remove_non_existent_repos(tx, &organizations).await?;
DB::remove_empty_organizations(tx).await?;
for org in organizations {
let organization_id = DB::upsert_organization(tx, &org.organization)
.await
Expand Down
11 changes: 11 additions & 0 deletions server/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,17 @@ impl DB {
Ok(())
}

pub async fn remove_empty_organizations(
tx: &mut Transaction<'static, Postgres>,
) -> anyhow::Result<()> {
sqlx::query!(
r#"DELETE FROM organizations WHERE id NOT IN (SELECT DISTINCT organization_id FROM repos)"#
)
.execute(tx.as_mut())
.await?;
Ok(())
}

pub async fn upsert_pull_request(
tx: &mut Transaction<'static, Postgres>,
repo_id: i32,
Expand Down

0 comments on commit fd3ed5d

Please sign in to comment.