Skip to content

Commit 622b266

Browse files
AyHaskiKSDaemon
andauthored
fix(client-vue3): Prevent heuristic call when initial query is empty in computed property validateQuery (#9656)
Co-authored-by: Konstantin Burkalev <[email protected]>
1 parent f1bb811 commit 622b266

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

packages/cubejs-client-vue3/src/QueryBuilder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ export default {
395395
}
396396

397397
// query heuristics should only apply on query change (not applied to the initial query)
398-
if (this.prevValidatedQuery !== null) {
398+
if (this.prevValidatedQuery !== null && isQueryPresent(validatedQuery)) {
399399
this.skipHeuristics = false;
400400
}
401401

packages/cubejs-client-vue3/tests/unit/QueryBuilder.spec.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,56 @@ describe('QueryBuilder.vue', () => {
10021002
expect(wrapper.vm.prevValidatedQuery.measures).not.toEqual(initialValidatedQuery.measures);
10031003
expect(wrapper.vm.prevValidatedQuery.dimensions).toEqual(initialValidatedQuery.dimensions);
10041004
});
1005+
1006+
it('should not set skipHeuristics to false if query is empty', async () => {
1007+
const cube = createCubeApi();
1008+
jest
1009+
.spyOn(cube, 'request')
1010+
.mockImplementation(fetchMock(load))
1011+
.mockImplementationOnce(fetchMock(meta));
1012+
1013+
const wrapper = shallowMount(QueryBuilder, {
1014+
propsData: {
1015+
cubeApi: cube,
1016+
query: {},
1017+
},
1018+
});
1019+
1020+
await flushPromises();
1021+
1022+
expect(wrapper.vm.skipHeuristics).toBeTruthy();
1023+
});
1024+
it('should set skipHeuristics to false if query is not empty and prevValidateQuery is not null', async () => {
1025+
const cube = createCubeApi();
1026+
jest
1027+
.spyOn(cube, 'request')
1028+
.mockImplementation(fetchMock(load))
1029+
.mockImplementationOnce(fetchMock(meta));
1030+
1031+
const wrapper = shallowMount(QueryBuilder, {
1032+
propsData: {
1033+
cubeApi: cube,
1034+
query: {
1035+
measures: ['Orders.count'],
1036+
timeDimensions: [
1037+
{
1038+
dimension: 'Orders.createdAt',
1039+
},
1040+
],
1041+
},
1042+
},
1043+
});
1044+
1045+
const initialValidatedQuery = {
1046+
measures: ['measure1'],
1047+
dimensions: ['dimension1'],
1048+
};
1049+
wrapper.setData({ prevValidatedQuery: initialValidatedQuery });
1050+
1051+
await flushPromises();
1052+
1053+
expect(wrapper.vm.skipHeuristics).toBeFalsy();
1054+
});
10051055
});
10061056
describe('orderMembers', () => {
10071057
it('does not contain time dimension if granularity is set to none', async () => {

0 commit comments

Comments
 (0)