Skip to content

Commit e528136

Browse files
Merge branch 'newarchitecture' into uj/newarch
2 parents 0c4bf0e + 45f07cd commit e528136

3 files changed

Lines changed: 88 additions & 22 deletions

File tree

api/utils/calculatedDataManager.js

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,36 @@ calculatedDataManager.longtask = async function(options) {
4949
options5.outputData(null, {"_id": options5.id, "running": true, "data": options5.current_data || {}});
5050
}
5151
}
52+
/**
53+
* Called if there is indication that calculations are in progress
54+
* @param {*} options6 - options
55+
* @param {*} timeoutObj - timeout object for returning data
56+
* @param {*} retry - number of retries left
57+
*/
58+
async function waitForData(options6, timeoutObj, retry) {
59+
retry = retry - 1;
60+
if (retry <= 0) {
61+
return;
62+
}
63+
else {
64+
try {
65+
var data = await common.db.collection(collection).findOne({_id: options6.id});
66+
if (data && data.data) {
67+
clearTimeout(timeoutObj);
68+
options6.outputData(null, {"_id": options6.id, "lu": data.lu, "data": data.data || {}});
69+
return;
70+
}
71+
else {
72+
setTimeout(function() {
73+
waitForData(options6, timeoutObj, retry);
74+
}, 2000);
75+
}
76+
}
77+
catch (e) {
78+
log.e("Error while getting calculated data", e);
79+
}
80+
}
81+
}
5282
/** switching to long task
5383
* @param {object} my_options - options
5484
* @param {object} my_options.query_data - query data
@@ -64,16 +94,8 @@ calculatedDataManager.longtask = async function(options) {
6494
await common.db.collection(collection).insertOne({_id: my_options.id, status: "calculating", "lu": new Date()});
6595
}
6696
catch (e) {
67-
//As could not insert try then getting result
68-
var data = await common.db.collection(collection).findOne({_id: options.id});
69-
if (data) {
70-
my_options.outputData(null, {"data": data.data, "lu": data.lu, "_id": options.id});
71-
return;
72-
}
73-
else {
74-
my_options.outputData(e, {"_id": my_options.id, "running": false, "error": true});
75-
}
76-
clearTimeout(timeout);
97+
//As could not insert, it might be calculating already
98+
waitForData(my_options, timeout, 10);
7799
return;
78100
}
79101
var start = Date.now().valueOf();
@@ -122,11 +144,17 @@ calculatedDataManager.longtask = async function(options) {
122144
}
123145
}
124146
else if (data.status === "calculating") {
125-
if (data.start && (new Date().getTime() - data.start) > 1000 * 60 * 60) {
147+
if (data.lu && (new Date().getTime() - new Date(data.lu).getTime()) < 1000 * 60 * 60) {
126148
//Return current data if there is any and let it know it is calculating
127-
clearTimeout(timeout);
128-
options.outputData(null, {"_id": options.id, "running": true, data: data.data || {}});
129-
return;
149+
if (data.data) {
150+
clearTimeout(timeout);
151+
options.outputData(null, {"_id": options.id, "running": true, data: data.data || {}});
152+
return;
153+
}
154+
else {
155+
//Do retry each few seconds to check if result is created
156+
waitForData(options, timeout, 10);
157+
}
130158
}
131159
else {
132160
common.db.collection(collection).deleteOne({_id: options.id}, function(ee) {

frontend/express/public/javascripts/countly/vue/components/datatable.js

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@
7575
return {
7676
controlParams: controlParams,
7777
lastSearchQuery: '',
78-
firstPage: 1
78+
firstPage: 1,
79+
lastControlParamsSnapshot: null
7980
};
8081
},
8182

@@ -328,14 +329,35 @@
328329
controlParams: {
329330
deep: true,
330331

331-
handler: _.debounce(function() {
332-
// Clear cursor history when search or filters change
333-
if (this.controlParams.searchQuery !== this.lastSearchQuery) {
334-
this.controlParams.cursorHistory = [];
335-
this.lastSearchQuery = this.controlParams.searchQuery;
332+
handler: _.debounce(function(newVal) {
333+
// Skip if this is the first run (no snapshot yet)
334+
if (!this.lastControlParamsSnapshot) {
335+
this.lastControlParamsSnapshot = this.getControlParamsSnapshot();
336+
return;
336337
}
337-
this.triggerExternalSource();
338-
this.setControlParams();
338+
339+
// Check if only internal/derived fields changed (like useCursorPagination)
340+
// These shouldn't trigger a fetch
341+
const meaningfulFields = ['page', 'perPage', 'searchQuery', 'sort', 'cursor', 'selectedDynamicCols'];
342+
const hasMeaningfulChange = meaningfulFields.some(field => {
343+
const newFieldVal = JSON.stringify(newVal[field]);
344+
const oldFieldVal = JSON.stringify(this.lastControlParamsSnapshot[field]);
345+
return newFieldVal !== oldFieldVal;
346+
});
347+
348+
// Only trigger fetch if meaningful user-initiated changes occurred
349+
if (hasMeaningfulChange) {
350+
// Clear cursor history when search or filters change
351+
if (this.controlParams.searchQuery !== this.lastSearchQuery) {
352+
this.controlParams.cursorHistory = [];
353+
this.lastSearchQuery = this.controlParams.searchQuery;
354+
}
355+
this.triggerExternalSource();
356+
this.setControlParams();
357+
}
358+
359+
// Update snapshot after processing
360+
this.lastControlParamsSnapshot = this.getControlParamsSnapshot();
339361
}, 500)
340362
},
341363

@@ -370,6 +392,8 @@
370392
},
371393

372394
mounted() {
395+
// Initialize snapshot on mount to prevent false positives
396+
this.lastControlParamsSnapshot = this.getControlParamsSnapshot();
373397
this.triggerExternalSource();
374398
},
375399

@@ -631,6 +655,19 @@
631655

632656
updateControlParams(newParams) {
633657
_.extend(this.controlParams, newParams);
658+
},
659+
660+
getControlParamsSnapshot() {
661+
// Create a snapshot of meaningful controlParams fields for comparison
662+
// Excludes internal state fields (cursorHistory, useCursorPagination) that get mutated during pagination
663+
return {
664+
page: this.controlParams.page,
665+
perPage: this.controlParams.perPage,
666+
searchQuery: this.controlParams.searchQuery,
667+
sort: JSON.parse(JSON.stringify(this.controlParams.sort || [])),
668+
cursor: this.controlParams.cursor,
669+
selectedDynamicCols: JSON.parse(JSON.stringify(this.controlParams.selectedDynamicCols || []))
670+
};
634671
}
635672
}
636673
};

plugins/data-manager/frontend/public/localization/data-manager.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ data-manager.transformation-method.subheading = Select transformation method tha
209209
data-manager.incoming = Incoming
210210
data-manager.existing = Existing
211211
data-manager.both = Both
212+
data-manager.clickhouse-incoming-only-message = When using ClickHouse, only incoming data transformations are supported.
212213
data-manager.rename-type = Rename Type
213214
data-manager.rename-type.tooltip = Rename Type
214215
data-manager.rename-with-value = Rename with Specific Value

0 commit comments

Comments
 (0)