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

Project owners read model - db read #6916

Merged
merged 18 commits into from
Apr 25, 2024
Merged

Project owners read model - db read #6916

merged 18 commits into from
Apr 25, 2024

Conversation

Tymek
Copy link
Member

@Tymek Tymek commented Apr 24, 2024

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

  • Create and test function combining projects list result with project owners read model results.
  • Create Schema update
  • Add project owners to the response when the feature flag is enabled

Internal ticket https://linear.app/unleash/issue/1-2318/get-project-owner-users-and-groups-from-db

Copy link

vercel bot commented Apr 24, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
unleash-monorepo-frontend ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 24, 2024 3:04pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
unleash-docs ⬜️ Ignored (Inspect) Visit Preview Apr 24, 2024 3:04pm

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a 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) 🚩

View detailed results in CodeScene

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a 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) 🚩

View detailed results in CodeScene

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a 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) 🚩

View detailed results in CodeScene

return groupsDict;
}

async getAllProjectOwners(): Promise<ProjectOwnersDictionary> {
Copy link
Member Author

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

@Tymek Tymek changed the title Project owners read model Project owners read model - db read Apr 24, 2024
@Tymek Tymek marked this pull request as ready for review April 24, 2024 15:17
Comment on lines +125 to +139
const projects = [
...new Set([...Object.keys(usersDict), ...Object.keys(groupsDict)]),
];

const dict = Object.fromEntries(
projects.map((project) => {
return [
project,
[
...(usersDict[project] || []),
...(groupsDict[project] || []),
],
];
}),
);
Copy link
Contributor

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 😅 ):

Suggested change
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 🤷🏼

Copy link
Member Author

Choose a reason for hiding this comment

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

done in next PR

@Tymek Tymek merged commit 477da7d into main Apr 25, 2024
12 of 13 checks passed
@Tymek Tymek deleted the feat/project-owners-api branch April 25, 2024 07:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants