-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
870744d
to
931e1e0
Compare
src/odata-to-abstract-sql.ts
Outdated
@@ -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 }; |
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.
You can name key
whatever so in cases like this it can help a lot to use a more descriptive name, eg
type AlreadyComputedFieldsLookup = { [key: string]: boolean }; | |
type AlreadyComputedFieldsLookup = { [fieldName: string]: boolean }; |
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 see, thanks!
src/odata-to-abstract-sql.ts
Outdated
@@ -991,11 +1004,16 @@ export class OData2AbstractSQL { | |||
fieldName: string, | |||
computed?: AbstractSqlQuery, | |||
alias: string = fieldName, | |||
alwaysCompileComputed: boolean = false, |
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.
Is this flag ever used?
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.
Yes, it's used in the case, where the actual computed fields a generated here:
https://github.com/balena-io-modules/odata-to-abstract-sql/blob/931e1e021310bc9788dd75bcc94da8bd06cdf789/src/odata-to-abstract-sql.ts#LL1713C1-L1719C9
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.
Ah, I didn't see it because the fn name isn't part of the diff
src/odata-to-abstract-sql.ts
Outdated
resource.fields.some( | ||
(f) => | ||
f.computed != null && | ||
!alreadyComputedFieldsLookup[resource.name + f.fieldName], |
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.
It's good to add some form of separator to further reduce the chances of accidental clashes, eg
!alreadyComputedFieldsLookup[resource.name + f.fieldName], | |
!alreadyComputedFieldsLookup[resource.name + '$' + f.fieldName], |
src/odata-to-abstract-sql.ts
Outdated
resource.fields.some( | ||
(f) => | ||
f.computed != null && | ||
!alreadyComputedFieldsLookup[resource.name + f.fieldName], |
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.
It's good to add some form of separator to further reduce the chances of accidental clashes, eg
!alreadyComputedFieldsLookup[resource.name + f.fieldName], | |
!alreadyComputedFieldsLookup[resource.name + '$' + f.fieldName], |
931e1e0
to
9bb741c
Compare
src/odata-to-abstract-sql.ts
Outdated
@@ -991,11 +1004,16 @@ export class OData2AbstractSQL { | |||
fieldName: string, | |||
computed?: AbstractSqlQuery, | |||
alias: string = fieldName, | |||
alwaysCompileComputed: boolean = false, |
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.
Ah, I didn't see it because the fn name isn't part of the diff
src/odata-to-abstract-sql.ts
Outdated
@@ -991,11 +1004,16 @@ export class OData2AbstractSQL { | |||
fieldName: string, | |||
computed?: AbstractSqlQuery, | |||
alias: string = fieldName, | |||
alwaysCompileComputed: boolean = false, |
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.
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
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.
Added a comment and found a better flag name
9bb741c
to
0229bd5
Compare
0d5403f
to
15e6a0d
Compare
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.
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/**/*", |
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 invalid json
.eslintrc.cjs
Outdated
sourceType: 'module', | ||
}, | ||
env: { | ||
jest: true, |
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.
We don't use jest?
Pull request was converted to draft
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 |
15e6a0d
to
6f3293d
Compare
@Page- Sorry for the confusion, I didn't push the changes when I commented on the remarks. Thanks for the review again. |
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]>
6f3293d
to
87c73d4
Compare
LGTM |
For each modelName the a
ComputedField
is only compiled into abstract-sql-query once. Aftewards it's used as ReferencedFieldChange-type: minor