瀏覽代碼

循环中.stop停止

visuddhinanda 2 年之前
父節點
當前提交
432f75122a
共有 2 個文件被更改,包括 13 次插入3 次删除
  1. 6 2
      app/Console/Commands/CacheDictPreference.php
  2. 7 1
      app/Console/Commands/CacheWbwPreference.php

+ 6 - 2
app/Console/Commands/CacheDictPreference.php

@@ -51,6 +51,7 @@ class CacheDictPreference extends Command
         $count = DB::select('SELECT count(*) from (
                      SELECT word,language from user_dicts group by word,language) T');
         $bar = $this->output->createProgressBar($count[0]->count);
+        $count = 0;
         foreach ($words as $key => $word) {
             $meaning = UserDict::where('word',$word->word)
                 ->where('language',$word->language)
@@ -63,8 +64,11 @@ class CacheDictPreference extends Command
                 Cache::put("{$prefix}/{$word->word}/{$word->language}",$m[0]);
             }
             $bar->advance();
-            if(\App\Tools\Tools::isStop()){
-                return 0;
+            $count++;
+            if($count%1000 === 0){
+                if(\App\Tools\Tools::isStop()){
+                    return 0;
+                }
             }
         }
         $bar->finish();

+ 7 - 1
app/Console/Commands/CacheWbwPreference.php

@@ -62,7 +62,7 @@ class CacheWbwPreference extends Command
                     [$this->option('editor')]);
             }
             $wbw = $wbw->groupBy(['wbw_word','type','editor_id'])->cursor();
-
+            $count = 0;
             $bar = $this->output->createProgressBar($count[0]->count);
             foreach ($wbw as $key => $value) {
                 $data = WbwAnalysis::where('wbw_word',$value->wbw_word)
@@ -72,6 +72,12 @@ class CacheWbwPreference extends Command
                                     ->value('data');
                 Cache::put("{$prefix}/{$value->wbw_word}/{$value->type}/{$value->editor_id}",$data);
                 $bar->advance();
+                $count++;
+                if($count%1000 === 0){
+                    if(\App\Tools\Tools::isStop()){
+                        return 0;
+                    }
+                }
             }
             $bar->finish();
         }