Skip to content

Commit

Permalink
delete targets in one go
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisnithin committed Nov 19, 2024
1 parent 76379ca commit fc5a6f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
18 changes: 3 additions & 15 deletions controlplane/src/core/repositories/OrganizationRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { BillingRepository } from './BillingRepository.js';
import { FederatedGraphRepository } from './FederatedGraphRepository.js';
import { OidcRepository } from './OidcRepository.js';
import { SubgraphRepository } from './SubgraphRepository.js';
import { TargetRepository } from './TargetRepository.js';

/**
* Repository for organization related operations.
Expand Down Expand Up @@ -855,27 +856,14 @@ export class OrganizationRepository {
return this.db.transaction(async (tx) => {
const oidcRepo = new OidcRepository(tx);
const fedGraphRepo = new FederatedGraphRepository(this.logger, tx, organizationId);
const subgraphRepo = new SubgraphRepository(this.logger, tx, organizationId);
const targetRepo = new TargetRepository(tx, organizationId);

const graphs = await fedGraphRepo.list({
limit: 0,
offset: 0,
});
const subgraphs = await subgraphRepo.list({
limit: 0,
offset: 0,
excludeFeatureSubgraphs: false,
});

// Delete graphs
const promises = [];
for (const graph of graphs) {
promises.push(fedGraphRepo.delete(graph.targetId));
}
for (const subgraph of subgraphs) {
promises.push(subgraphRepo.delete(subgraph.targetId));
}
await Promise.all(promises);
await targetRepo.deleteAll();

// Clean up blob storage
const blobPromises = [];
Expand Down
4 changes: 4 additions & 0 deletions controlplane/src/core/repositories/TargetRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ export class TargetRepository {

await this.db.update(targets).set({ namespaceId: newNamespaceId }).where(inArray(targets.id, targetIds));
}

public async deleteAll() {
await this.db.delete(targets).where(and(eq(targets.organizationId, this.organizationId)));
}
}

0 comments on commit fc5a6f4

Please sign in to comment.