-
Notifications
You must be signed in to change notification settings - Fork 345
chore: Normalize User.tms #10992
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
chore: Normalize User.tms #10992
Conversation
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.
I'm not sure solving this in code is the right call for the tms
field as it's used in the connection logic which should be kept lean.
I'm thinking about making a UserWithTeams
view for this use case.
packages/client/modules/userDashboard/components/UserTasksHeader/UserTasksHeader.tsx
Outdated
Show resolved
Hide resolved
Views are clunky when altering the underlying table. We can achieve the same with just a custom loader. |
b1f681c
to
3099ba3
Compare
packages/server/postgres/migrations/2025-03-18T15:55:35.723Z_normalizeUserTms.ts
Outdated
Show resolved
Hide resolved
packages/server/postgres/migrations/2025-03-18T15:55:35.723Z_normalizeUserTms.ts
Outdated
Show resolved
Hide resolved
packages/server/postgres/migrations/2025-03-18T15:55:35.723Z_normalizeUserTms.ts
Outdated
Show resolved
Hide resolved
User.tms must reflect User<-TeamMember->Team relation considering Team.isArchived and TeamMember.isNotRemoved. We query it always with the User and thus it's sensible to keep it in the User. To keep it consistent, we're updating it with triggers now.
898ee9d
to
2854b82
Compare
.onConflict((oc) => oc.columns(['id']).doUpdateSet({isNotRemoved: true})) | ||
.execute() | ||
|
||
const res = await db |
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.
This takes around 20s on staging and affects 250 users.
Description
Fixes #9932
We query User.tms quite often to check permissions, so it's useful to be denormalized. To avoid update errors, I added triggers for Team and TeamMember operations which update the array.
There is also some inconsistent data in the database, I've added a migration to clean that up as well.
Demo
Nothing should change for the user.
Testing scenarios
Joining, leaving and archiving teams
Final checklist