Skip to content
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

[server] Optimize getTeamMembers (N queries → 1 query) #4482

Closed
wants to merge 1 commit into from

Conversation

jankeromnes
Copy link
Contributor

@jankeromnes jankeromnes commented Jun 11, 2021

Fixes #4470

I've also added a test (passed! ✅) and getting team member infos still works fine:

Screenshot 2021-06-11 at 11 18 47

@@ -36,6 +36,7 @@ import { DBWorkspaceInstance } from './typeorm/entity/db-workspace-instance';
const typeorm = testContainer.get<TypeORM>(TypeORM);
const mnr = await typeorm.getConnection();
await mnr.getRepository(DBUser).delete({});
await mnr.getRepository(DBIdentity).delete({});
Copy link
Contributor Author

@jankeromnes jankeromnes Jun 11, 2021

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 in UserDBSpec:

  1) UserDBSpec
       createUserAndFindById:

      AssertionError: expected { Object (id, creationDate, ...) } to have deep property 'identities' of [ Array(1) ], but got [ Array(1) ]
      + expected - actual

           "authId": "1234"
           "authName": "gero"
           "authProviderId": "GitHub"
           "deleted": false
      -    "primaryEmail": "tom@example.com"
      +    "primaryEmail": [undefined]
           "readonly": false
           "tokens": []
         }
       ]

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:

@OneToMany(type => DBIdentity,
identity => identity.user,
{
eager: true,
cascadeInsert: true,
cascadeUpdate: true
// , cascadeRemove: true // In the docs but not the code???
}
)

My drive-by fix here was to also clean up the DBIdentity repo after cleaning up DBUser (in both UserDBSpec and TeamDBSpec). But that pre-existing comment makes a good point -- maybe we should cascadeRemove identities?

Copy link
Member

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.

@csweichel
Copy link
Contributor

csweichel commented Jun 11, 2021

/werft run

👍 started the job as gitpod-build-jx-optimize-get-team-members.5

@jankeromnes
Copy link
Contributor Author

Anyone please approve. Can be safely merged any time.

Copy link
Contributor

@csweichel csweichel left a comment

Choose a reason for hiding this comment

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

LGTM

@jankeromnes
Copy link
Contributor Author

Thanks!

This was already merged as 236d81d (as part of #4490).

@jankeromnes jankeromnes deleted the jx/optimize-get-team-members branch June 21, 2021 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[server] Optimize query behind getTeamMembers
4 participants