Explorar el Código

Merge pull request #1836 from visuddhinanda/laravel

模版渲染 没有设置channel 报错
visuddhinanda hace 2 años
padre
commit
44eae2a462

+ 20 - 10
app/Console/Commands/UpgradeCompound.php

@@ -5,18 +5,16 @@ use Illuminate\Console\Command;
 use Illuminate\Support\Facades\Storage;
 use App\Models\WordIndex;
 use App\Models\WbwTemplate;
-use App\Models\UserDict;
 use App\Tools\TurboSplit;
 use App\Http\Api\DictApi;
 use Illuminate\Support\Facades\DB;
-use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Http;
 
 class UpgradeCompound extends Command
 {
     /**
      * The name and signature of the console command.
-     * php artisan upgrade:compound --api=https://staging.wikipali.org/api
+     * php -d memory_limit=1024M artisan upgrade:compound  --api=https://next.wikipali.org/api --from=182852 --to=30000
      * @var string
      */
     protected $signature = 'upgrade:compound {word?} {--book=} {--debug} {--test} {--continue} {--api=} {--from=} {--to=}';
@@ -48,12 +46,11 @@ class UpgradeCompound extends Command
     public function handle()
     {
         if(\App\Tools\Tools::isStop()){
-            return 0;
-        }
-        if(file_exists(base_path('.stop'))){
             $this->info('.stop exists');
             return 0;
         }
+        $this->info('['.date('Y-m-d H:i:s', time()).'] upgrade:compound start');
+
         $dict_id = DictApi::getSysDict('robot_compound');
         if(!$dict_id){
             $this->error('没有找到 robot_compound 字典');
@@ -118,14 +115,22 @@ class UpgradeCompound extends Command
             $min = WordIndex::min('id');
             $max = WordIndex::max('id');
             if($this->option('from')){
-                $min = $min + $this->option('from');
+                $from = $min + $this->option('from');
+            }else{
+                $from = $min;
+            }
+            if($this->option('to')){
+                $to = $min + $this->option('to');
+            }else{
+                $to = $max;
             }
-            $words = WordIndex::whereBetween('id',[$min,$max])
+            $words = WordIndex::whereBetween('id',[$from,$to])
                             ->where('len','>',7)
+                            ->where('len','<',51)
                             ->orderBy('id')
                             ->selectRaw('word as real')
                             ->cursor();
-            $count = $max - $min + 1;
+            $count = $to - $from + 1;
         }
 
 		$sn = 0;
@@ -135,6 +140,7 @@ class UpgradeCompound extends Command
             if(\App\Tools\Tools::isStop()){
                 return 0;
             }
+            $sn++;
             $startAt = microtime(true);
 
 			$ts = new TurboSplit();
@@ -145,7 +151,8 @@ class UpgradeCompound extends Command
             $parts = $ts->splitA($word->real);
             $time = round(microtime(true) - $startAt,2);
             $percent = (int)($sn * 100 / $count);
-            $this->info("[{$percent}%] {$word->real}  {$time}s");
+
+            $this->info("[{$percent}%][{$sn}] {$word->real}  {$time}s");
 
             $resultCount = 0;
             foreach ($parts as $part) {
@@ -187,6 +194,9 @@ class UpgradeCompound extends Command
             }
 		}
         $this->upload($wordIndex,$result,$this->option('api'));
+
+        $this->info('['.date('Y-m-d H:i:s', time()).'] upgrade:compound finished');
+
         return 0;
     }
 

+ 9 - 0
app/Http/Api/TemplateRender.php

@@ -104,6 +104,15 @@ class TemplateRender{
             $channelId = null;
         }
 
+
+        if(count($this->channelInfo)===0){
+            Log::error('channel is null');
+            $output = [
+                "word" => $word,
+                'innerHtml' => '',
+            ];
+            return $output;
+        }
         $channelInfo = $this->channelInfo[0];
         if(Str::isUuid($channelId)){
             $lang = Channel::where('uid',$channelId)->value('lang');

+ 5 - 5
app/Tools/TurboSplit.php

@@ -2,12 +2,12 @@
 namespace App\Tools;
 require_once __DIR__.'/../../public/app/public/casesuf.inc';
 
-use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\DB;
 use App\Models\WordPart;
 use App\Models\UserDict;
 use Illuminate\Support\Arr;
+use App\Tools\RedisClusters;
 
 class TurboSplit
 {
@@ -178,7 +178,7 @@ class TurboSplit
         $search = $word;
 
 		//获取单词权重
-		$row = Cache::remember('palicanon/wordpart/weight/'.$search,
+		$row = RedisClusters::remember('palicanon/wordpart/weight/'.$search,
                 config('mint.cache.expire') ,
                 function() use($search) {
                     return WordPart::where('word',$search)->value('weight');
@@ -207,7 +207,7 @@ class TurboSplit
 			$base_weight = 0;
 			$len = 0;
 			foreach ($newWord as $x => $x_value) {
-				$row = Cache::remember('palicanon/wordpart/weight/'.$search,
+				$row = RedisClusters::remember('palicanon/wordpart/weight/'.$search,
                         config('mint.cache.expire') ,
                         function() use($x) {
                             return WordPart::where('word',$x)->value('weight');
@@ -237,7 +237,7 @@ class TurboSplit
 
 		$isFound = false;
 		$count = 0;
-		$wordPart  = Cache::remember("turbosplit/part/{$word}",
+		$wordPart  = RedisClusters::remember("turbosplit/part/{$word}",
                         config('mint.cache.expire'),
                         function() use($word){
                             return implode(',',$this->dict_lookup($word));
@@ -253,7 +253,7 @@ class TurboSplit
 
 		//fomular of confidence value 信心值计算公式
 		if ($isFound) {
-			$cf  = Cache::remember("turbosplit/confidence/".$word,
+			$cf  = RedisClusters::remember("turbosplit/confidence/".$word,
                     config('mint.cache.expire'),
                     function() use($word,$count,$case_len){
                         $len = mb_strlen($word, "UTF-8") - $case_len;