浏览代码

feat: 并发窗口优化

zhangjie 11 月之前
父节点
当前提交
d76112c3d2

+ 1 - 1
config.sample.json

@@ -1,3 +1,3 @@
 {
-  "downloadProcessCount": 2
+  "downloadProcessCount": 1
 }

+ 29 - 19
electron/db/modelApi/trackTask.ts

@@ -145,29 +145,39 @@ export async function getUnfinishTrackTaskDetails(
   trackTaskId: number,
   count = 10
 ) {
-  const limitCount = Math.max(10, Math.min(100, count));
-  const rows = await TrackTaskDetail.findAll({
-    where: { status: TRACK_TASK_DETAIL_STATUS.INIT, trackTaskId },
-    limit: limitCount,
-  }).catch((err) => {
-    console.dir(err);
-  });
-  if (!rows || !rows.length) return null;
+  const t = await sequelize.transaction();
 
-  await TrackTaskDetail.update(
-    {
-      status: TRACK_TASK_DETAIL_STATUS.RUNNING,
-    },
-    {
-      where: {
-        id: {
-          [Op.in]: rows.map((row) => row.dataValues.id),
+  try {
+    const limitCount = Math.max(10, Math.min(100, count));
+    const rows = await TrackTaskDetail.findAll({
+      where: { status: TRACK_TASK_DETAIL_STATUS.INIT, trackTaskId },
+      limit: limitCount,
+      transaction: t,
+    });
+
+    if (rows.length) {
+      await TrackTaskDetail.update(
+        {
+          status: TRACK_TASK_DETAIL_STATUS.RUNNING,
         },
-      },
+        {
+          where: {
+            id: {
+              [Op.in]: rows.map((row) => row.dataValues.id),
+            },
+          },
+          transaction: t,
+        }
+      );
     }
-  );
 
-  return rows.map((row) => row.dataValues);
+    await t.commit();
+
+    return rows.map((row) => row.dataValues);
+  } catch (error) {
+    await t.rollback();
+    return Promise.reject(error);
+  }
 }
 
 export async function updateTrackTaskDetailStatus(data: {

+ 1 - 1
src/views/base/track-export/taskProgress.vue

@@ -198,7 +198,7 @@
       appConfig.downloadProcessCount,
       getExportUrl()
     );
-    // window.electron.startWinProcess(1, getExportUrl());
+    // window.electron.startWinProcess(2, getExportUrl());
   }
 
   function updateTaskFilerInfo(data: FilterDataType | null) {

+ 8 - 6
src/views/base/track-export/trackTaskExport.vue

@@ -37,7 +37,7 @@
   const task = ref({} as TrackTaskData);
   const trackConfig = ref({} as TrackConfigType);
   const queueConcurrency = 4;
-  const groupCount = 20;
+  const groupCount = 10;
 
   function addLog(content: string, type?: 'info' | 'error') {
     window.api.logger(`win:${winId} ${content}`, type);
@@ -50,11 +50,13 @@
       return;
     }
 
-    const res = await window.db.getUnfinishTrackTaskDetails(
-      task.value.id,
-      groupCount
-    );
-    if (!res) {
+    const res = await window.db
+      .getUnfinishTrackTaskDetails(task.value.id, groupCount)
+      .catch((e) => {
+        addLog(`00-获取任务失败:${e.message}`, 'error');
+      });
+
+    if (!res || !res.length) {
       addLog(`00-无任务`);
       addSetTimeout(TASK_KEY, startGroupTask, 1 * 1000);
       return;