-
-
Notifications
You must be signed in to change notification settings - Fork 713
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
Project owners read model - db read #6916
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
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.
✅ Code Health Quality Gates: OK
- Declining Code Health: 2 findings(s) 🚩
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.
✅ Code Health Quality Gates: OK
- Declining Code Health: 1 findings(s) 🚩
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.
✅ Code Health Quality Gates: OK
- Declining Code Health: 1 findings(s) 🚩
return groupsDict; | ||
} | ||
|
||
async getAllProjectOwners(): Promise<ProjectOwnersDictionary> { |
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.
Splitting it in 2 private methods makes the main one more readable to me, so that's what I did
const projects = [ | ||
...new Set([...Object.keys(usersDict), ...Object.keys(groupsDict)]), | ||
]; | ||
|
||
const dict = Object.fromEntries( | ||
projects.map((project) => { | ||
return [ | ||
project, | ||
[ | ||
...(usersDict[project] || []), | ||
...(groupsDict[project] || []), | ||
], | ||
]; | ||
}), | ||
); |
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 is optional, but there's a lot of spreading here. We're not necessarily doing it in a loop, but it's a lot more iterations than we need. How about doing something like this instead (coded in github, so might not work directly 😅 ):
const projects = [ | |
...new Set([...Object.keys(usersDict), ...Object.keys(groupsDict)]), | |
]; | |
const dict = Object.fromEntries( | |
projects.map((project) => { | |
return [ | |
project, | |
[ | |
...(usersDict[project] || []), | |
...(groupsDict[project] || []), | |
], | |
]; | |
}), | |
); | |
for (const [project, groups] of Object.entries(groupsDict) { | |
if (project in usersDict) { | |
usersDict[project] = usersDict[project].concat(groups) | |
} else { | |
usersDict[project] = groups | |
} | |
} |
and then return the usersDict
instead? That'll save us a lot of iteration and feels more readable to me 🤷🏼
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.
done in next PR
About the changes
Implementation of the logic for fetching project owners.
Based on pattern documented in https://docs.getunleash.io/contributing/ADRs/back-end/write-model-vs-read-models
Next up
Internal ticket https://linear.app/unleash/issue/1-2318/get-project-owner-users-and-groups-from-db