-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[server] Optimize getTeamMembers (N queries → 1 query) #4482
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import { TypeORM } from './typeorm/typeorm'; | |
import { DBTeam } from './typeorm/entity/db-team'; | ||
import { DBTeamMembership } from './typeorm/entity/db-team-membership'; | ||
import { DBUser } from './typeorm/entity/db-user'; | ||
import { DBIdentity } from './typeorm/entity/db-identity'; | ||
|
||
@suite class TeamDBSpec { | ||
|
||
|
@@ -35,6 +36,7 @@ import { DBUser } from './typeorm/entity/db-user'; | |
await manager.getRepository(DBTeam).delete({}); | ||
await manager.getRepository(DBTeamMembership).delete({}); | ||
await manager.getRepository(DBUser).delete({}); | ||
await manager.getRepository(DBIdentity).delete({}); | ||
} | ||
|
||
@test(timeout(10000)) | ||
|
@@ -48,5 +50,18 @@ import { DBUser } from './typeorm/entity/db-user'; | |
expect(dbResult[0].name).to.eq('Ground Control'); | ||
} | ||
|
||
@test(timeout(10000)) | ||
public async findTeamMembers() { | ||
const user = await this.userDb.newUser(); | ||
user.identities.push({ authProviderId: 'GitHub', authId: '1234', authName: 'Major Tom', primaryEmail: '[email protected]' }); | ||
await this.userDb.storeUser(user); | ||
const team = await this.db.createTeam(user.id, 'Flight Crew'); | ||
const members = await this.db.findMembersByTeam(team.id); | ||
expect(members.length).to.eq(1); | ||
expect(members[0].userId).to.eq(user.id); | ||
expect(members[0].primaryEmail).to.eq('[email protected]'); | ||
} | ||
|
||
} | ||
|
||
module.exports = new TeamDBSpec() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@geropl On a side note, while manipulating identities in
TeamDBSpec
, I stumbled on a weird failure inUserDBSpec
:See: https://werft.gitpod-dev.com/job/gitpod-build-jx-optimize-get-team-members.2
That's when I realized that identities are not deleted when users are deleted:
gitpod/components/gitpod-db/src/typeorm/entity/db-user.ts
Lines 41 to 49 in a6c5481
My drive-by fix here was to also clean up the
DBIdentity
repo after cleaning upDBUser
(in bothUserDBSpec
andTeamDBSpec
). But that pre-existing comment makes a good point -- maybe we should cascadeRemove identities?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasn't the reason that we are not cascade deleting related items that it needs to go through dbsync? i.e. we need to enable soft-deletion for that.