Browse Source

update: statistical service

v2board 2 years ago
parent
commit
24b4c174c1
2 changed files with 8 additions and 2 deletions
  1. 2 1
      app/Console/Commands/V2boardStatistics.php
  2. 6 1
      app/Services/StatisticalService.php

+ 2 - 1
app/Console/Commands/V2boardStatistics.php

@@ -66,10 +66,11 @@ class V2boardStatistics extends Command
                 'record_at' => $recordAt
             ])) {
                 DB::rollback();
-                break;
+                throw new \Exception('stat user fail');
             }
         }
         DB::commit();
+        $statService->clearStatUser();
     }
 
     private function statOrder()

+ 6 - 1
app/Services/StatisticalService.php

@@ -7,7 +7,7 @@ class StatisticalService {
     protected $userStats;
     protected $recordAt;
 
-    public function __construct($recordAt = '')
+    public function __construct($recordAt = NULL)
     {
         ini_set('memory_limit', -1);
         $this->recordAt = $recordAt ?? strtotime(date('Y-m-d'));
@@ -50,4 +50,9 @@ class StatisticalService {
         }
         return $stats;
     }
+
+    public function clearStatUser()
+    {
+        Cache::forget("stat_user_{$this->recordAt}");
+    }
 }