Răsfoiți Sursa

联赛有变化时重置版本号

flyzto 1 lună în urmă
părinte
comite
5069265c9a
1 a modificat fișierele cu 34 adăugiri și 15 ștergeri
  1. 34 15
      pinnacle/main.js

+ 34 - 15
pinnacle/main.js

@@ -26,6 +26,21 @@ const GLOBAL_DATA = {
   loopResultTime: 0,
 };
 
+const resetVersionsCount = () => {
+  GLOBAL_DATA.straightFixturesVersion = 0;
+  GLOBAL_DATA.specialFixturesVersion = 0;
+  GLOBAL_DATA.straightOddsVersion = 0;
+  GLOBAL_DATA.specialsOddsVersion = 0;
+
+  GLOBAL_DATA.straightFixturesCount = 0;
+  GLOBAL_DATA.specialFixturesCount = 0;
+}
+
+const incrementVersionsCount = () => {
+  GLOBAL_DATA.straightFixturesCount = 0;
+  GLOBAL_DATA.specialFixturesCount = 0;
+}
+
 
 /**
  * 获取指定时区当前日期或时间
@@ -85,6 +100,14 @@ const pinnacleGet = async (endpoint, params) => {
 // };
 
 
+const isArrayEqualUnordered = (arr1, arr2) => {
+  if (arr1.length !== arr2.length) return false;
+  const s1 = [...arr1].sort();
+  const s2 = [...arr2].sort();
+  return s1.every((v, i) => v === s2[i]);
+}
+
+
 const getFiltedGames = () => {
   return new Promise(resolve => {
     const updateFiltedGames = () => {
@@ -102,11 +125,18 @@ const getFiltedGames = () => {
           };
         });
 
-        GLOBAL_DATA.filtedLeagues = [...new Set(games.map(game => game.leagueId).filter(leagueId => leagueId))];
+        const newFiltedLeagues = [...new Set(games.map(game => game.leagueId).filter(leagueId => leagueId))];
+
+        if (!isArrayEqualUnordered(newFiltedLeagues, GLOBAL_DATA.filtedLeagues)) {
+          Logs.outDev('filted leagues changed', newFiltedLeagues);
+          resetVersionsCount();
+          GLOBAL_DATA.filtedLeagues = newFiltedLeagues;
+        }
+
         GLOBAL_DATA.filtedGames = games.map(game => game.eventId).filter(eventId => eventId);
 
         resolve();
-        setTimeout(updateFiltedGames, 1000 * 30);
+        setTimeout(updateFiltedGames, 1000 * 60);
       })
       .catch(err => {
         Logs.err('failed to update filted games:', err.message);
@@ -734,21 +764,10 @@ const pinnacleDataLoop = () => {
     let loopDelay = 1000 * 5;
     if (!loopActive) {
       loopDelay = 1000 * 60;
-      GLOBAL_DATA.straightFixturesVersion = 0;
-      GLOBAL_DATA.specialFixturesVersion = 0;
-      GLOBAL_DATA.straightOddsVersion = 0;
-      GLOBAL_DATA.specialsOddsVersion = 0;
-
-      GLOBAL_DATA.straightFixturesCount = 0;
-      GLOBAL_DATA.specialFixturesCount = 0;
-      // GLOBAL_DATA.straightOddsCount = 0;
-      // GLOBAL_DATA.specialsOddsCount = 0;
+      resetVersionsCount();
     }
     else {
-      GLOBAL_DATA.straightFixturesCount++;
-      GLOBAL_DATA.specialFixturesCount++;
-      // GLOBAL_DATA.straightOddsCount++;
-      // GLOBAL_DATA.specialsOddsCount++;
+      incrementVersionsCount();
     }
     setTimeout(pinnacleDataLoop, loopDelay);
   });