Skip to content

Commit d00f9c0

Browse files
authored
[db] Move towards sync deletion (away from PeriodicDeleter) - step I/II (#18833)
* [db] Tables: remove entries without deletionColumn (not used anymore) * [db] DBAuthProviderEntry: Switch to sync deletion * [db] DBTokenEntry: Switch to sync deletion * [db] DBTeamMembership: Switch to sync deletion * [db] DBUserStorageResource: remove from periodic deleter * [db] DBGitpodToken: Switch to sync deletion * [db] DBProjectUsage: Switch to sync deletion * [db] DBUserSSHPublicKey: Switch to sync deletion
1 parent 1ad6654 commit d00f9c0

File tree

5 files changed

+16
-114
lines changed

5 files changed

+16
-114
lines changed

components/gitpod-db/src/tables.ts

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,6 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider
3838
timeColumn: "_lastModified",
3939
deletionColumn: "deleted",
4040
},
41-
{
42-
name: "d_b_oauth_auth_code_entry",
43-
primaryKeys: ["id"],
44-
timeColumn: "_lastModified",
45-
},
46-
{
47-
name: "d_b_installation_admin",
48-
primaryKeys: ["id"],
49-
timeColumn: "_lastModified",
50-
},
5141
{
5242
name: "d_b_volume_snapshot",
5343
primaryKeys: ["id"],
@@ -72,52 +62,12 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider
7262
primaryKeys: ["id"],
7363
timeColumn: "_lastModified",
7464
},
75-
{
76-
name: "d_b_user_storage_resource",
77-
primaryKeys: ["userId", "uri"],
78-
timeColumn: "_lastModified",
79-
deletionColumn: "deleted",
80-
dependencies: ["d_b_user"],
81-
},
82-
{
83-
name: "d_b_workspace_instance_user",
84-
primaryKeys: ["instanceId", "userId"],
85-
timeColumn: "_lastModified",
86-
dependencies: ["d_b_user"],
87-
},
88-
{
89-
name: "d_b_workspace_report_entry",
90-
primaryKeys: ["uid"],
91-
timeColumn: "time",
92-
dependencies: [],
93-
},
94-
{
95-
name: "d_b_snapshot",
96-
primaryKeys: ["id"],
97-
timeColumn: "creationTime",
98-
dependencies: [],
99-
},
100-
{
101-
name: "d_b_email_domain_filter",
102-
primaryKeys: ["domain"],
103-
timeColumn: "_lastModified",
104-
},
105-
{
106-
name: "d_b_app_installation",
107-
primaryKeys: ["platform", "installationID", "state"],
108-
timeColumn: "creationTime",
109-
},
11065
{
11166
name: "d_b_token_entry",
11267
primaryKeys: ["uid"],
11368
deletionColumn: "deleted",
11469
timeColumn: "_lastModified",
11570
},
116-
{
117-
name: "d_b_user_env_var",
118-
primaryKeys: ["id", "userId"],
119-
timeColumn: "_lastModified",
120-
},
12171
{
12272
name: "d_b_gitpod_token",
12373
primaryKeys: ["tokenHash"],
@@ -137,17 +87,6 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider
13787
deletionColumn: "deleted",
13888
timeColumn: "_lastModified",
13989
},
140-
{
141-
name: "d_b_code_sync_collection",
142-
primaryKeys: ["userId", "collection"],
143-
timeColumn: "_lastModified",
144-
},
145-
{
146-
name: "d_b_code_sync_resource",
147-
primaryKeys: ["userId", "kind", "rev", "collection"],
148-
timeColumn: "created",
149-
dependencies: ["d_b_code_sync_collection"],
150-
},
15190
{
15291
name: "d_b_team",
15392
primaryKeys: ["id"],
@@ -196,16 +135,6 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider
196135
deletionColumn: "deleted",
197136
timeColumn: "_lastModified",
198137
},
199-
{
200-
name: "d_b_cost_center",
201-
primaryKeys: ["id", "creationTime"],
202-
timeColumn: "_lastModified",
203-
},
204-
{
205-
name: "d_b_usage",
206-
primaryKeys: ["id"],
207-
timeColumn: "_lastModified",
208-
},
209138
{
210139
name: "d_b_stripe_customer",
211140
primaryKeys: ["stripeCustomerId"],
@@ -218,11 +147,6 @@ export class GitpodTableDescriptionProvider implements TableDescriptionProvider
218147
timeColumn: "_lastModified",
219148
deletionColumn: "deleted",
220149
},
221-
{
222-
name: "d_b_linked_in_profile",
223-
primaryKeys: ["id"],
224-
timeColumn: "_lastModified",
225-
},
226150
];
227151

228152
public getSortedTables(): TableDescription[] {

components/gitpod-db/src/typeorm/auth-provider-entry-db-impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export class AuthProviderEntryDBImpl implements AuthProviderEntryDB {
4848

4949
// 2. then mark as deleted
5050
const repo = await this.getAuthProviderRepo();
51-
await repo.update({ id }, { deleted: true });
51+
await repo.delete({ id });
5252
}
5353

5454
async findAll(exceptOAuthRevisions: string[] = []): Promise<AuthProviderEntry[]> {

components/gitpod-db/src/typeorm/project-db-impl.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ export class ProjectDBImpl extends TransactionalDBImpl<ProjectDB> implements Pro
118118
await projectInfoRepo.update(projectId, { deleted: true });
119119
}
120120
const projectUsageRepo = await this.getProjectUsageRepo();
121-
const usage = await projectUsageRepo.findOne({ projectId, deleted: false });
122-
if (usage) {
123-
await projectUsageRepo.update(projectId, { deleted: true });
124-
}
121+
await projectUsageRepo.delete({ projectId });
125122
}
126123

127124
public async findProjectEnvironmentVariable(

components/gitpod-db/src/typeorm/team-db-impl.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,7 @@ export class TeamDBImpl extends TransactionalDBImpl<TeamDB> implements TeamDB {
328328
"The given user is not currently a member of this organization or does not exist.",
329329
);
330330
}
331-
membership.deleted = true;
332-
await membershipRepo.save(membership);
331+
await membershipRepo.delete(membership);
333332
}
334333

335334
public async findTeamMembershipInviteById(inviteId: string): Promise<TeamMembershipInvite> {

components/gitpod-db/src/typeorm/user-db-impl.ts

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import {
2929
OAuthUser,
3030
} from "@jmondi/oauth2-server";
3131
import { inject, injectable, optional } from "inversify";
32-
import { EntityManager, Equal, Not, Repository } from "typeorm";
32+
import { EntityManager, Equal, FindOperator, Not, Repository } from "typeorm";
3333
import { v4 as uuidv4 } from "uuid";
3434
import {
3535
BUILTIN_WORKSPACE_PROBE_USER_ID,
@@ -256,27 +256,12 @@ export class TypeORMUserDBImpl extends TransactionalDBImpl<UserDB> implements Us
256256

257257
public async deleteGitpodToken(tokenHash: string): Promise<void> {
258258
const repo = await this.getGitpodTokenRepo();
259-
await repo.query(
260-
`
261-
UPDATE d_b_gitpod_token AS gt
262-
SET gt.deleted = TRUE
263-
WHERE tokenHash = ?;
264-
`,
265-
[tokenHash],
266-
);
259+
await repo.delete({ tokenHash });
267260
}
268261

269262
public async deleteGitpodTokensNamedLike(userId: string, namePattern: string): Promise<void> {
270263
const repo = await this.getGitpodTokenRepo();
271-
await repo.query(
272-
`
273-
UPDATE d_b_gitpod_token AS gt
274-
SET gt.deleted = TRUE
275-
WHERE userId = ?
276-
AND name LIKE ?
277-
`,
278-
[userId, namePattern],
279-
);
264+
await repo.delete({ userId, name: new FindOperator("like", namePattern) });
280265
}
281266

282267
public async storeSingleToken(identity: Identity, token: Token): Promise<TokenEntry> {
@@ -309,16 +294,14 @@ export class TypeORMUserDBImpl extends TransactionalDBImpl<UserDB> implements Us
309294

310295
public async deleteExpiredTokenEntries(date: string): Promise<void> {
311296
const repo = await this.getTokenRepo();
312-
await repo.query(
313-
`
314-
UPDATE d_b_token_entry AS te
315-
SET te.deleted = TRUE
316-
WHERE te.expiryDate != ''
317-
AND te.refreshable != 1
318-
AND te.expiryDate <= ?;
319-
`,
320-
[date],
321-
);
297+
await repo
298+
.createQueryBuilder()
299+
.delete()
300+
.from(DBTokenEntry)
301+
.where("expiryDate != ''")
302+
.andWhere("refreshable != 1")
303+
.andWhere("expiryDate <= :date", { date })
304+
.execute();
322305
}
323306

324307
public async updateTokenEntry(tokenEntry: Partial<TokenEntry> & Pick<TokenEntry, "uid">): Promise<void> {
@@ -331,8 +314,7 @@ export class TypeORMUserDBImpl extends TransactionalDBImpl<UserDB> implements Us
331314
const repo = await this.getTokenRepo();
332315
for (const existing of existingTokens) {
333316
if (!shouldDelete || shouldDelete(existing)) {
334-
existing.deleted = true;
335-
await repo.save(existing);
317+
await repo.delete(existing.uid);
336318
}
337319
}
338320
}
@@ -481,7 +463,7 @@ export class TypeORMUserDBImpl extends TransactionalDBImpl<UserDB> implements Us
481463

482464
public async deleteSSHPublicKey(userId: string, id: string): Promise<void> {
483465
const repo = await this.getSSHPublicKeyRepo();
484-
await repo.update({ userId, id }, { deleted: true });
466+
await repo.delete({ userId, id });
485467
}
486468

487469
public async findAllUsers(

0 commit comments

Comments
 (0)