|
|
@@ -8,6 +8,9 @@ import { Select, Button, Input, Space } from 'tdesign-react';
|
|
|
import { DeleteIcon } from 'tdesign-icons-react';
|
|
|
import 'tdesign-react/es/style/index.css';
|
|
|
|
|
|
+import PQueue from 'p-queue';
|
|
|
+const queue = new PQueue({ concurrency: 5 });
|
|
|
+
|
|
|
const {Option} = Select;
|
|
|
|
|
|
function formatTimestamp(timestamp) {
|
|
|
@@ -82,6 +85,17 @@ function parseStockData(data) {
|
|
|
};
|
|
|
}
|
|
|
|
|
|
+const flushMemoryDbData = async (data, symbol) => {
|
|
|
+ // console.log('Invoking flush-memory-db-data', data.length, symbol);
|
|
|
+ try {
|
|
|
+ await window.electronAPI.flushMemoryDbData(data, symbol);
|
|
|
+ // const result = await window.electronAPI.flushMemoryDbData(data, symbol);
|
|
|
+ // console.log('Flush successful', result);
|
|
|
+ } catch (error) {
|
|
|
+ // console.error('Error flushing memory DB data', error);
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
export default () => {
|
|
|
const [isActivation, setIsActivation] = React.useState(false);
|
|
|
const [activationCode, setActivationCode] = React.useState();
|
|
|
@@ -153,6 +167,7 @@ export default () => {
|
|
|
const symbolInfo = symbolOptions.find((item)=> item.id === loginSymbol)
|
|
|
const ws = new WebSocket(`ws://localhost:${symbolInfo.port}`);
|
|
|
let ref = heatmapRef.current
|
|
|
+ // let prevFlushMemoryDbDataTimestamp = new Date().getTime()
|
|
|
|
|
|
console.log('ws创建完成')
|
|
|
ws.onmessage = function(event) {
|
|
|
@@ -161,8 +176,17 @@ export default () => {
|
|
|
let stock = parseStockData(message)
|
|
|
|
|
|
ref.addData(stock)
|
|
|
- window.electronAPI.flushMemoryDbData(ref.data, symbolInfo.symbol)
|
|
|
|
|
|
+ // 每1秒刷新一次后台的数据
|
|
|
+ // let now = new Date().getTime()
|
|
|
+ // if (now - 1000 > prevFlushMemoryDbDataTimestamp) {
|
|
|
+ // // 使用 slice 方法提取最后 5000 条数据,保存到本地
|
|
|
+ // const startIndex = Math.max(ref.data.length - 5000, 0);
|
|
|
+ // let saveData = ref.data.slice(startIndex);
|
|
|
+ // queue.add(() => flushMemoryDbData(saveData, symbolInfo.symbol));
|
|
|
+ // }
|
|
|
+
|
|
|
+ // 数据推送进度条
|
|
|
if (progressRef.current !== null) {
|
|
|
progressRef.current.innerHTML = ` 等待数据推送 ${(100 * ref.data.length / ref.windowLength + 1).toFixed(0)}% ...`
|
|
|
|