Skip to content

Commit

Permalink
feat: add pagination to operations page in check summary (#1377)
Browse files Browse the repository at this point in the history
  • Loading branch information
JivusAyrus authored Nov 18, 2024
1 parent fde6885 commit e61d4f1
Show file tree
Hide file tree
Showing 10 changed files with 4,302 additions and 4,147 deletions.
7,950 changes: 3,990 additions & 3,960 deletions connect-go/gen/proto/wg/cosmo/platform/v1/platform.pb.go

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions connect/src/wg/cosmo/platform/v1/platform_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3969,6 +3969,16 @@ export class GetCheckOperationsRequest extends Message<GetCheckOperationsRequest
*/
namespace = "";

/**
* @generated from field: int32 limit = 4;
*/
limit = 0;

/**
* @generated from field: int32 offset = 5;
*/
offset = 0;

constructor(data?: PartialMessage<GetCheckOperationsRequest>) {
super();
proto3.util.initPartial(data, this);
Expand All @@ -3980,6 +3990,8 @@ export class GetCheckOperationsRequest extends Message<GetCheckOperationsRequest
{ no: 1, name: "check_id", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 2, name: "graph_name", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 3, name: "namespace", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 4, name: "limit", kind: "scalar", T: 5 /* ScalarType.INT32 */ },
{ no: 5, name: "offset", kind: "scalar", T: 5 /* ScalarType.INT32 */ },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): GetCheckOperationsRequest {
Expand Down Expand Up @@ -4028,6 +4040,11 @@ export class GetCheckOperationsResponse extends Message<GetCheckOperationsRespon
*/
clientTrafficCheckSkipped = false;

/**
* @generated from field: int32 totalOperationsCount = 6;
*/
totalOperationsCount = 0;

constructor(data?: PartialMessage<GetCheckOperationsResponse>) {
super();
proto3.util.initPartial(data, this);
Expand All @@ -4041,6 +4058,7 @@ export class GetCheckOperationsResponse extends Message<GetCheckOperationsRespon
{ no: 3, name: "traffic_check_days", kind: "scalar", T: 5 /* ScalarType.INT32 */ },
{ no: 4, name: "created_at", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 5, name: "client_traffic_check_skipped", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
{ no: 6, name: "totalOperationsCount", kind: "scalar", T: 5 /* ScalarType.INT32 */ },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): GetCheckOperationsResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ export function createIgnoreOverridesForAllOperations(
return await opts.db.transaction(async (tx) => {
const auditLogRepo = new AuditLogRepository(tx);
const operationsRepo = new OperationsRepository(tx, graph.id);
const affectedOperations = await schemaCheckRepo.getAffectedOperationsByCheckId(req.checkId);
const affectedOperations = await schemaCheckRepo.getAffectedOperationsByCheckId({
checkId: req.checkId,
});

for (const affectedOperation of affectedOperations) {
const affectedChanges = await operationsRepo.createIgnoreAllOverride({
Expand Down
28 changes: 27 additions & 1 deletion controlplane/src/core/bufservices/check/getCheckOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export function getCheckOperations(
trafficCheckDays: 0,
createdAt: '',
clientTrafficCheckSkipped: false,
totalOperationsCount: 0,
};
}

Expand All @@ -55,10 +56,30 @@ export function getCheckOperations(
trafficCheckDays: 0,
createdAt: '',
clientTrafficCheckSkipped: false,
totalOperationsCount: 0,
};
}

const affectedOperations = await schemaCheckRepo.getAffectedOperationsByCheckId(req.checkId);
// check that the limit is less than the max option provided in the ui
if (req.limit > 200) {
return {
response: {
code: EnumStatusCode.ERR,
details: 'Invalid limit',
},
operations: [],
trafficCheckDays: 0,
createdAt: '',
clientTrafficCheckSkipped: false,
totalOperationsCount: 0,
};
}

const affectedOperations = await schemaCheckRepo.getAffectedOperationsByCheckId({
checkId: req.checkId,
limit: req.limit,
offset: req.offset,
});

const { trafficCheckDays } = await schemaCheckRepo.getFederatedGraphConfigForCheckId(req.checkId, graph.id);

Expand All @@ -72,6 +93,10 @@ export function getCheckOperations(
namespaceId: graph.namespaceId,
});

const affectedOperationsCount = await schemaCheckRepo.getAffectedOperationsCountByCheckId({
checkId: req.checkId,
});

return {
response: {
code: EnumStatusCode.OK,
Expand All @@ -91,6 +116,7 @@ export function getCheckOperations(
trafficCheckDays,
createdAt: check.timestamp,
clientTrafficCheckSkipped: check.clientTrafficCheckSkipped || false,
totalOperationsCount: affectedOperationsCount,
};
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ export function toggleChangeOverridesForAllOperations(
const auditLogRepo = new AuditLogRepository(tx);
const operationsRepo = new OperationsRepository(tx, graph.id);

const affectedOperations = await schemaCheckRepo.getAffectedOperationsByCheckId(req.checkId);
const affectedOperations = await schemaCheckRepo.getAffectedOperationsByCheckId({
checkId: req.checkId,
});
const checkDetails = await subgraphRepo.checkDetails(req.checkId, graph.targetId);

if (!checkDetails) {
Expand Down
59 changes: 54 additions & 5 deletions controlplane/src/core/repositories/SchemaCheckRepository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { and, eq, inArray, or, sql } from 'drizzle-orm';
import _ from 'lodash';
import { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
import { VCSContext } from '@wundergraph/cosmo-connect/dist/platform/v1/platform_pb';
import { and, eq, inArray, sql } from 'drizzle-orm';
import { PostgresJsDatabase } from 'drizzle-orm/postgres-js';
import _ from 'lodash';
import pLimit from 'p-limit';
import { NewSchemaChangeOperationUsage } from '../../db/models.js';
import * as schema from '../../db/schema.js';
Expand Down Expand Up @@ -247,7 +247,15 @@ export class SchemaCheckRepository {
.execute();
}

public async getAffectedOperationsByCheckId(checkId: string) {
public async getAffectedOperationsByCheckId({
checkId,
limit,
offset,
}: {
checkId: string;
limit?: number;
offset?: number;
}) {
const changeActionIds = (
await this.db.query.schemaCheckChangeAction.findMany({
where: and(
Expand All @@ -261,7 +269,7 @@ export class SchemaCheckRepository {
).map((r) => r.id);

if (changeActionIds.length > 0) {
return await this.db
const dbQuery = this.db
.selectDistinctOn([schema.schemaCheckChangeActionOperationUsage.hash], {
hash: schema.schemaCheckChangeActionOperationUsage.hash,
name: schema.schemaCheckChangeActionOperationUsage.name,
Expand All @@ -280,11 +288,52 @@ export class SchemaCheckRepository {
.from(schema.schemaCheckChangeActionOperationUsage)
.where(inArray(schema.schemaCheckChangeActionOperationUsage.schemaCheckChangeActionId, changeActionIds))
.groupBy(({ hash, name, type }) => [hash, name, type]);

if (limit) {
dbQuery.limit(limit);
}

if (offset) {
dbQuery.offset(offset);
}

return await dbQuery.execute();
}

return [];
}

public async getAffectedOperationsCountByCheckId({ checkId }: { checkId: string }) {
const changeActionIds = (
await this.db.query.schemaCheckChangeAction.findMany({
where: and(
eq(schema.schemaCheckChangeAction.schemaCheckId, checkId),
eq(schema.schemaCheckChangeAction.isBreaking, true),
),
columns: {
id: true,
},
})
).map((r) => r.id);

if (changeActionIds.length > 0) {
const result = await this.db
.selectDistinctOn([schema.schemaCheckChangeActionOperationUsage.hash], {
hash: schema.schemaCheckChangeActionOperationUsage.hash,
name: schema.schemaCheckChangeActionOperationUsage.name,
type: schema.schemaCheckChangeActionOperationUsage.type,
})
.from(schema.schemaCheckChangeActionOperationUsage)
.where(inArray(schema.schemaCheckChangeActionOperationUsage.schemaCheckChangeActionId, changeActionIds))
.groupBy(({ hash, name, type }) => [hash, name, type])
.execute();

return result.length;
}

return 0;
}

public createSchemaCheckCompositions(data: { schemaCheckID: string; compositions: ComposedFederatedGraph[] }) {
if (data.compositions.length === 0) {
return;
Expand Down
3 changes: 3 additions & 0 deletions proto/wg/cosmo/platform/v1/platform.proto
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ message GetCheckOperationsRequest {
string check_id = 1;
string graph_name = 2;
string namespace = 3;
int32 limit = 4;
int32 offset = 5;
}

message GetCheckOperationsResponse {
Expand All @@ -526,6 +528,7 @@ message GetCheckOperationsResponse {
int32 traffic_check_days = 3;
string created_at = 4;
bool client_traffic_check_skipped = 5;
int32 totalOperationsCount = 6;
}

message GetOperationContentRequest {
Expand Down
Loading

0 comments on commit e61d4f1

Please sign in to comment.