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

refactor(core): Continue moving typeorm operators to repositories (no-changelog) #8186

Merged
merged 5 commits into from
Jan 2, 2024

Conversation

ivov
Copy link
Contributor

@ivov ivov commented Dec 29, 2023

Follow-up to: #8163

@n8n-assistant n8n-assistant bot added core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team labels Dec 29, 2023
@@ -106,17 +106,24 @@ export = {

if (['owner', 'admin'].includes(req.user.globalRole.name)) {
if (tags) {
const workflowIds = await getWorkflowIdsViaTags(parseTagNames(tags));
const workflowIds = await Container.get(TagRepository).getWorkflowIdsViaTags(
Copy link
Member

Choose a reason for hiding this comment

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

Once we are done moving all DB stuff into repositories, we should start moving all logic into services, and make sure that the public api and the rest api reuse as much code as possible. we have currently too much duplication in the public api.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd love to know why the Public API required so much duplication.

Copy link
Member

Choose a reason for hiding this comment

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

our code used to be a lot less re-usable because of how it was structured in the past.

packages/cli/src/UserManagement/PermissionChecker.ts Outdated Show resolved Hide resolved
@@ -89,7 +91,10 @@ export class CollaborationService {
if (workflowUserIds.length === 0) {
return;
}
const users = await this.userService.getByIds(this.userService.getManager(), workflowUserIds);
const users = await this.userRepository.getByIds(
this.userService.getManager(),
Copy link
Member

Choose a reason for hiding this comment

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

not sure why UserService.getManager was added, but this is unnecessary, and should be removed. if userRepository.getByIds wants to accept a optional transaction, then we should update it to
async getByIds(ids: string[], transaction: EntityManager = this.manager) instead of passing around entity-managers like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

getByIds requires a transaction because I'm moving all persistence logic to the persistence layer and that is how this method existed originally. We should refactor to create more generalized reusable methods in the repositories, but for now I'd like to focus on finishing moving all persistence logic to the persistence layer, which is a ton of work as it is 🙈

@@ -138,7 +138,7 @@ export class AuthController {
}

try {
user = await this.userService.findOneOrFail({ where: {} });
user = await this.userRepository.findOneOrFail({ where: {}, relations: ['globalRole'] });
Copy link
Member

Choose a reason for hiding this comment

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

in the long run we should aim to move more code out of these controllers, and avoid having repositories as direct dependencies in them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here I wasn't 100% sure what to do since the service method was a paper-thin wrapper for the repository method.

packages/cli/src/controllers/me.controller.ts Show resolved Hide resolved
packages/cli/src/controllers/passwordReset.controller.ts Outdated Show resolved Hide resolved
Copy link

cypress bot commented Jan 2, 2024

3 flaky tests on run #3553 ↗︎

0 325 5 0 Flakiness 3

Details:

🌳 🖥️ browsers:node18.12.0-chrome107 🤖 ivov 🗃️ e2e/*
Project: n8n Commit: c509ab6280
Status: Passed Duration: 07:13 💡
Started: Jan 2, 2024 3:28 PM Ended: Jan 2, 2024 3:35 PM
Flakiness  17-sharing.cy.ts • 1 flaky test

View Output Video

Test Artifacts
Sharing > should work for admin role on credentials created by others (also can share it with themselves) Screenshots Video
Flakiness  24-ndv-paired-item.cy.ts • 1 flaky test

View Output Video

Test Artifacts
NDV > resolves expression with default item when input node is not parent, while still pairing items Screenshots Video
Flakiness  29-templates.cy.ts • 1 flaky test

View Output Video

Test Artifacts
Templates > should save template id with the workflow Screenshots Video

Review all test suite changes for PR #8186 ↗︎

Copy link
Contributor

github-actions bot commented Jan 2, 2024

✅ All Cypress E2E specs passed

@ivov ivov merged commit 40c1eee into master Jan 2, 2024
25 checks passed
@ivov ivov deleted the continue-moving-typeorm-operators-to-repositories branch January 2, 2024 16:53
@Joffcom
Copy link
Member

Joffcom commented Jan 3, 2024

Got released with [email protected]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Enhancement outside /nodes-base and /editor-ui n8n team Authored by the n8n team Released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants