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

Optimize Duplications of ComputedField queries #126

Merged
merged 1 commit into from
Nov 24, 2023

Conversation

fisehara
Copy link
Contributor

For each modelName the a ComputedField is only compiled into abstract-sql-query once. Aftewards it's used as ReferencedField

Change-type: minor

@flowzone-app flowzone-app bot enabled auto-merge April 26, 2023 10:24
@fisehara fisehara force-pushed the fisehara/optimize-computed-fields branch 6 times, most recently from 870744d to 931e1e0 Compare May 3, 2023 10:51
@@ -117,6 +117,8 @@ type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
type RequiredField<T, F extends keyof T> = Overwrite<T, Required<Pick<T, F>>>;
type AliasedResource = RequiredField<Resource, 'tableAlias'>;

type AlreadyComputedFieldsLookup = { [key: string]: boolean };
Copy link
Contributor

Choose a reason for hiding this comment

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

You can name key whatever so in cases like this it can help a lot to use a more descriptive name, eg

Suggested change
type AlreadyComputedFieldsLookup = { [key: string]: boolean };
type AlreadyComputedFieldsLookup = { [fieldName: string]: boolean };

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 see, thanks!

@@ -991,11 +1004,16 @@ export class OData2AbstractSQL {
fieldName: string,
computed?: AbstractSqlQuery,
alias: string = fieldName,
alwaysCompileComputed: boolean = false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this flag ever used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I didn't see it because the fn name isn't part of the diff

resource.fields.some(
(f) =>
f.computed != null &&
!alreadyComputedFieldsLookup[resource.name + f.fieldName],
Copy link
Contributor

Choose a reason for hiding this comment

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

It's good to add some form of separator to further reduce the chances of accidental clashes, eg

Suggested change
!alreadyComputedFieldsLookup[resource.name + f.fieldName],
!alreadyComputedFieldsLookup[resource.name + '$' + f.fieldName],

resource.fields.some(
(f) =>
f.computed != null &&
!alreadyComputedFieldsLookup[resource.name + f.fieldName],
Copy link
Contributor

Choose a reason for hiding this comment

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

It's good to add some form of separator to further reduce the chances of accidental clashes, eg

Suggested change
!alreadyComputedFieldsLookup[resource.name + f.fieldName],
!alreadyComputedFieldsLookup[resource.name + '$' + f.fieldName],

@fisehara fisehara force-pushed the fisehara/optimize-computed-fields branch from 931e1e0 to 9bb741c Compare May 16, 2023 09:18
@fisehara fisehara requested a review from Page- May 16, 2023 11:39
@@ -991,11 +1004,16 @@ export class OData2AbstractSQL {
fieldName: string,
computed?: AbstractSqlQuery,
alias: string = fieldName,
alwaysCompileComputed: boolean = false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I didn't see it because the fn name isn't part of the diff

@@ -991,11 +1004,16 @@ export class OData2AbstractSQL {
fieldName: string,
computed?: AbstractSqlQuery,
alias: string = fieldName,
alwaysCompileComputed: boolean = false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment giving a brief/basic explanation of what the flag is for so that future people looking at the code have a starting point for understanding it please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment and found a better flag name

@fisehara fisehara force-pushed the fisehara/optimize-computed-fields branch from 9bb741c to 0229bd5 Compare June 28, 2023 15:33
@fisehara fisehara requested a review from Page- June 28, 2023 15:34
@fisehara fisehara force-pushed the fisehara/optimize-computed-fields branch 2 times, most recently from 0d5403f to 15e6a0d Compare October 17, 2023 11:32
Copy link
Contributor

@Page- Page- left a comment

Choose a reason for hiding this comment

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

A bunch of my previous review comments still stand, and also I'd like to see the version bumps as a separate PR so they can be merged separately based upon whichever part is approved first

tsconfig.json Outdated
@@ -15,7 +15,7 @@
"allowJs": true
},
"include": [
"src/**/*"
"src/**/*",
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 invalid json

.eslintrc.cjs Outdated
sourceType: 'module',
},
env: {
jest: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't use jest?

@Page- Page- marked this pull request as draft October 17, 2023 15:28
auto-merge was automatically disabled October 17, 2023 15:28

Pull request was converted to draft

@Page-
Copy link
Contributor

Page- commented Oct 17, 2023

And I've just seen it is a separate PR.. I've converted this to draft until #137 is merged as it depends on that

@fisehara fisehara force-pushed the fisehara/optimize-computed-fields branch from 15e6a0d to 6f3293d Compare November 17, 2023 12:21
@fisehara
Copy link
Contributor Author

@Page- Sorry for the confusion, I didn't push the changes when I commented on the remarks. Thanks for the review again.

@fisehara fisehara requested a review from Page- November 17, 2023 12:22
@fisehara fisehara marked this pull request as ready for review November 17, 2023 12:24
For each modelName the a `ComputedField` is only compiled into abstract-sql-query once. Afterwards it's used as ReferencedField

Change-type: minor
Signed-off-by: fisehara <[email protected]>
@fisehara fisehara force-pushed the fisehara/optimize-computed-fields branch from 6f3293d to 87c73d4 Compare November 17, 2023 12:25
@flowzone-app flowzone-app bot enabled auto-merge November 17, 2023 12:27
@fisehara
Copy link
Contributor Author

LGTM

@flowzone-app flowzone-app bot merged commit c7c9679 into master Nov 24, 2023
48 checks passed
@flowzone-app flowzone-app bot deleted the fisehara/optimize-computed-fields branch November 24, 2023 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants