sea-chart 1.1.31 → 1.1.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/context.js
CHANGED
|
@@ -1,41 +1,51 @@
|
|
|
1
|
+
import { uniqueId } from 'lodash-es';
|
|
1
2
|
import context from '../../context';
|
|
2
3
|
import { getErrorMessage } from '..';
|
|
3
4
|
import intl from '../../intl';
|
|
5
|
+
import concurrencyManager from '../concurrency-manager';
|
|
4
6
|
import BaseUtils from './base-utils';
|
|
5
7
|
import SQLStatisticsUtils from './sql-statistics-utils';
|
|
6
8
|
import OriginalDataUtils from './original-data-utils';
|
|
7
9
|
class ChartUtils {}
|
|
8
|
-
ChartUtils.calculateChart = (chart, value, callback) => {
|
|
10
|
+
ChartUtils.calculateChart = async (chart, value, callback) => {
|
|
9
11
|
if (!BaseUtils.isValidExistChart(value.tables, chart)) {
|
|
10
12
|
const tip_message = 'Please_complete_the_chart_configuration_first';
|
|
11
13
|
return callback && callback('', tip_message, null);
|
|
12
14
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
15
|
+
const id = uniqueId();
|
|
16
|
+
const requestData = () => {
|
|
17
|
+
context.queryChartResult({
|
|
18
|
+
chart,
|
|
19
|
+
tables: value.tables,
|
|
20
|
+
onSuccess: async function (res) {
|
|
21
|
+
var _res$data;
|
|
22
|
+
let dataSources = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SQLStatisticsUtils.dataSources;
|
|
23
|
+
// reolve request and start next request
|
|
24
|
+
concurrencyManager.removeRequest(id);
|
|
25
|
+
const {
|
|
26
|
+
success,
|
|
27
|
+
error_message
|
|
28
|
+
} = res.data;
|
|
29
|
+
if (!success) {
|
|
30
|
+
const errMsg = intl.get(error_message);
|
|
31
|
+
callback && callback(errMsg, '', null);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (dataSources === OriginalDataUtils.dataSources) {
|
|
35
|
+
OriginalDataUtils.calculateChart(chart, value, callback);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
await SQLStatisticsUtils.calculateChart(chart, value, callback, (res === null || res === void 0 ? void 0 : (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.results) || []);
|
|
39
|
+
},
|
|
40
|
+
onFail: err => {
|
|
41
|
+
concurrencyManager.removeRequest(id);
|
|
42
|
+
let errorMessage = getErrorMessage(err);
|
|
43
|
+
callback && callback(errorMessage, '', null);
|
|
27
44
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
await SQLStatisticsUtils.calculateChart(chart, value, callback, (res === null || res === void 0 ? void 0 : (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.results) || []);
|
|
33
|
-
},
|
|
34
|
-
onFail: err => {
|
|
35
|
-
let errorMessage = getErrorMessage(err);
|
|
36
|
-
callback && callback(errorMessage, '', null);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
requestData.id = id;
|
|
48
|
+
concurrencyManager.applyRequest(requestData);
|
|
39
49
|
};
|
|
40
50
|
ChartUtils.calculateStaticChart = (chart, value, statisticalResult, callback) => {
|
|
41
51
|
if (!BaseUtils.isValidExistChart(value.tables, chart)) {
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
class ConcurrencyManager {
|
|
2
|
+
constructor(concurrentCount) {
|
|
3
|
+
this.concurrentCount = concurrentCount;
|
|
4
|
+
this.requestList = [];
|
|
5
|
+
this.queue = [];
|
|
6
|
+
}
|
|
7
|
+
applyRequest(req) {
|
|
8
|
+
if (this.requestList.length < this.concurrentCount) {
|
|
9
|
+
this.requestList.push(req);
|
|
10
|
+
req();
|
|
11
|
+
} else {
|
|
12
|
+
this.queue.push({
|
|
13
|
+
req
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
removeRequest(id) {
|
|
18
|
+
const index = this.requestList.findIndex(req => req.id === id);
|
|
19
|
+
if (index > -1) {
|
|
20
|
+
this.requestList.splice(index, 1);
|
|
21
|
+
}
|
|
22
|
+
if (this.queue.length > 0) {
|
|
23
|
+
const {
|
|
24
|
+
req
|
|
25
|
+
} = this.queue.shift();
|
|
26
|
+
this.requestList.push(req);
|
|
27
|
+
req();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
// request once a time
|
|
32
|
+
const concurrencyManager = new ConcurrencyManager(1);
|
|
33
|
+
export default concurrencyManager;
|