Skip to content

Implement soft deletion of pending github events #13455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export class GithubSubscriptionReconciler {
event: JSON.stringify(evt),
githubUserId: evt.payload.marketplace_purchase.account.id.toString(),
id: evt.id,
type: `marketplace_purchase.${evt.payload.action}`
type: `marketplace_purchase.${evt.payload.action}`,
deleted: false
});
}
}
Expand Down Expand Up @@ -267,4 +268,4 @@ interface MarketplaceAccountListing {
email?: string;
marketplace_pending_change?: any; // this seems broken on the GitHub side
marketplace_purchase: Webhooks.EmitterWebhookEvent<"marketplace_purchase">["payload"];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ export class DBPendingGithubEvent implements PendingGithubEvent {

@Column()
event: string;

// This column triggers the db-sync deletion mechanism. It's not intended for public consumption.
@Column()
deleted: boolean;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ export class TypeORMPendingGithubEventDBImpl implements PendingGithubEventDB {
return await repo
.createQueryBuilder("pghe")
.where(`pghe.githubUserId = :accountId AND pghe.type LIKE :tpe`, { accountId, tpe: `${type}%` })
.andWhere(`pghe.deleted = 0`)
.getMany();
}

public async delete(evt: PendingGithubEvent) {
// pending events is not synchronized via DB sync so we can delete it
(await this.getRepo()).delete(evt.id);
(await this.getRepo()).update(evt.id, { deleted: true });
}

public async findWithUser(type: string): Promise<PendingGithubEventWithUser[]> {
Expand All @@ -55,6 +55,7 @@ export class TypeORMPendingGithubEventDBImpl implements PendingGithubEventDB {
.innerJoinAndSelect("ident.user", "user")
.where('ident.authProviderId = "Public-GitHub"')
.andWhere(`ident.deleted != true`)
.andWhere(`pghe.deleted = 0`)
.orderBy("pghe.creationDate", "ASC")
.getMany();

Expand Down
1 change: 1 addition & 0 deletions components/gitpod-protocol/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ export interface PendingGithubEvent {
creationDate: Date;
type: string;
event: string;
deleted: boolean;
}

export interface Snapshot {
Expand Down