Skip to content

Commit

Permalink
fix: Cache allDefinitions Object.assign invocations to optimize highl…
Browse files Browse the repository at this point in the history
…y dynamic schema SQL execution (#4894)

* fix: Cache allDefinitions Object.assign invocations to optimize highly dynamic schema SQL execution

* chore: Cache allDefinitions Object.assign invocations to optimize highly dynamic schema SQL execution -- rewrite with spread as it's faster
  • Loading branch information
paveltiunov committed Jul 12, 2022
1 parent 67c90fe commit ad3fea8
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions packages/cubejs-schema-compiler/src/compiler/CubeSymbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,32 +44,46 @@ export class CubeSymbols {
}

createCube(cubeDefinition) {
let measures;
let dimensions;
let segments;
const cubeObject = Object.assign({
allDefinitions(type) {
let superDefinitions = {};

if (cubeDefinition.extends) {
superDefinitions = super.allDefinitions(type);
return {
...super.allDefinitions(type),
...cubeDefinition[type]
};
} else {
// TODO We probably do not need this shallow copy
return { ...cubeDefinition[type] };
}

return Object.assign({}, superDefinitions, cubeDefinition[type]);
},
get measures() {
return this.allDefinitions('measures');
if (!measures) {
measures = this.allDefinitions('measures');
}
return measures;
},
set measures(v) {
// Dont allow to modify
},

get dimensions() {
return this.allDefinitions('dimensions');
if (!dimensions) {
dimensions = this.allDefinitions('dimensions');
}
return dimensions;
},
set dimensions(v) {
// Dont allow to modify
},

get segments() {
return this.allDefinitions('segments');
if (!segments) {
segments = this.allDefinitions('segments');
}
return segments;
},
set segments(v) {
// Dont allow to modify
Expand Down

0 comments on commit ad3fea8

Please sign in to comment.