فهرست منبع

ID 获取中单方案优化

flyzto 3 ماه پیش
والد
کامیت
4a7e63ff3a
1فایلهای تغییر یافته به همراه32 افزوده شده و 19 حذف شده
  1. 32 19
      server/models/GamesPs.js

+ 32 - 19
server/models/GamesPs.js

@@ -172,6 +172,18 @@ const syncBaseList = ({ marketType, games }) => {
 
 }
 
+/**
+ * 清理基准比赛列表
+ */
+const cleanupBaseList = () => {
+  const baseList = GAMES.Baselist;
+  const nowTime = Date.now();
+  const expireTime = nowTime - 1000*60*60*3;
+  Object.keys(baseList).forEach(marketType => {
+    baseList[marketType] = baseList[marketType].filter(item => item.timestamp < expireTime);
+  });
+}
+
 /**
  * 更新比赛列表
  */
@@ -268,16 +280,6 @@ const syncBaseEvents = ({ mk, games, outrights }) => {
             value: odds[key]?.v ?? 0,
             origin: odds[key]?.r
           }
-          // if (key.includes('os') && !odds[key]) {
-          //   return { key, value: 1 };
-          // }
-          // else {
-          //   return {
-          //     key,
-          //     value: odds[key]?.v ?? 0,
-          //     origin: odds[key]?.r
-          //   }
-          // }
         });
         if (label == 'jqs') {
           match = match.filter(item => item.value !== 0);
@@ -294,13 +296,10 @@ const syncBaseEvents = ({ mk, games, outrights }) => {
           return item.match.every(entry => entry.value !== 0);
         }
       });
+
+      game.matches = matches; // matches 也记录下来
+
       let uptime = evtime ?? 0;
-      // if (evtime && sptime) {
-      //   uptime = Math.min(evtime, sptime);
-      // }
-      // else if (!sptime) {
-      //   uptime = evtime ?? 0;
-      // }
       return { ...gameInfo, matches, uptime };
     });
 
@@ -828,9 +827,22 @@ const getSolution = async (sid) => {
  * 通过比赛 ID 获取中单方案
  */
 const getSolutionsByIds = async (ids) => {
-  const idsSet = new Set(ids.map(item => +item));
-  const solutions = Object.values(GAMES.Solutions).filter(item => idsSet.has(item.info.id));
-  return solutions;
+  const baseList = Object.values(GAMES.Baselist).flat();
+  const baseMap = new Map(baseList.map(item => [item.eventId, item]));
+  const result = {};
+  ids.forEach(id => {
+    const baseGame = baseMap.get(id);
+    result[id] = {};
+    result[id].matches = baseGame?.matches ?? [];
+    result[id].sols = [];
+  });
+  Object.values(GAMES.Solutions).forEach(item => {
+    const { info: { id } } = item;
+    if (result[id]) {
+      result[id].sols.push(item);
+    }
+  });
+  return result;
 }
 
 /**
@@ -865,6 +877,7 @@ const solutionsCleanup = () => {
  * 定时清理盘口信息
  */
 setInterval(() => {
+  cleanupBaseList();
   solutionsCleanup();
   gamesRelationCleanup();
 }, 1000*30);