Browse Source

v1.1.5

1. 修复内存泄漏错误
2. 限制持久化的数据量
3. 修复某些场景下会很卡的bug
skyffire 1 year ago
parent
commit
71d448be73
3 changed files with 27 additions and 3 deletions
  1. 1 1
      example/package.json
  2. 25 1
      example/src/App.js
  3. 1 1
      src/index.js

+ 1 - 1
example/package.json

@@ -1,7 +1,7 @@
 {
   "name": "heatmap",
   "homepage": ".",
-  "version": "1.1.4",
+  "version": "1.1.5",
   "private": true,
   "main": "main.js",
   "scripts": {

+ 25 - 1
example/src/App.js

@@ -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)}% ...`
 

+ 1 - 1
src/index.js

@@ -1047,7 +1047,7 @@ export default class StockHeatmap extends React.Component {
       // 延迟日志
       if (this.windowedData.length > 1) {
         let last = this.windowedData[this.windowedData.length - 1]
-        console.log(new Date().getTime() - last.time, last)
+        // console.log(new Date().getTime() - last.time, last)
       }
 
       this.windowPosition = position;