Skip to content

Fix for Webhook Event GC #12559

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 1, 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
4 changes: 2 additions & 2 deletions components/gitpod-db/src/typeorm/webhook-event-db-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ export class WebhookEventDBImpl implements WebhookEventDB {
d.setDate(d.getDate() - ageInDays);
const expirationDate = d.toISOString();
const query = repo
.createQueryBuilder("event")
.createQueryBuilder()
.update()
.set({ deleted: true })
.where("event.creationTime < :expirationDate", { expirationDate });
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for some reasons, aliasing doesn't work with typeorm here. 🤷🏻

.where("creationTime <= :expirationDate", { expirationDate });
if (typeof limit === "number") {
query.limit(limit);
}
Expand Down
16 changes: 16 additions & 0 deletions components/gitpod-db/src/webhook-event-db.spec.db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ export class WebhookEventDBSpec {
expect(updated.type, "type should not be updated").to.equal("push");
expect(updated.rawEvent, "rawEvent should not be updated").to.equal("payload as string");
}

@test public async testDeleteOldEvents() {
const cloneUrl = "http://gitlab.local/project/repo";
await this.db.createEvent({
rawEvent: "payload as string",
status: "received",
type: "push",
cloneUrl,
});

await this.db.deleteOldEvents(0, 1);

const event = (await this.db.findByCloneUrl(cloneUrl))[0];
expect(event, "should be found").to.be.not.undefined;
expect((event as DBWebhookEvent).deleted, "should be marked as deleted").to.be.true;
}
}

module.exports = WebhookEventDBSpec;