Просмотр исходного кода

Merge pull request #1648 from visuddhinanda/laravel

sentCanReadCount remove cache
visuddhinanda 2 лет назад
Родитель
Сommit
003e8bb33c

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

@@ -8,6 +8,7 @@ use App\Models\ProgressChapter;
 use App\Models\Channel;
 use App\Models\Channel;
 use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Log;
+use App\Tools\RedisClusters;
 
 
 class ExportChapterIndex extends Command
 class ExportChapterIndex extends Command
 {
 {
@@ -63,7 +64,7 @@ class ExportChapterIndex extends Command
 
 
         $publicChannels = Channel::where('status',30)->select('uid')->get();
         $publicChannels = Channel::where('status',30)->select('uid')->get();
         $rows = ProgressChapter::whereIn('channel_id',$publicChannels)->count();
         $rows = ProgressChapter::whereIn('channel_id',$publicChannels)->count();
-        Cache::put("/export/chapter/count",$rows,3600*10);
+        RedisClusters::put("/export/chapter/count",$rows,3600*10);
         $bar = $this->output->createProgressBar($rows);
         $bar = $this->output->createProgressBar($rows);
         foreach (ProgressChapter::whereIn('channel_id',$publicChannels)
         foreach (ProgressChapter::whereIn('channel_id',$publicChannels)
                                 ->select(['uid','book','para',
                                 ->select(['uid','book','para',

+ 8 - 6
app/Console/Commands/ExportOffline.php

@@ -6,6 +6,8 @@ use Illuminate\Console\Command;
 use Illuminate\Support\Facades\Storage;
 use Illuminate\Support\Facades\Storage;
 use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Log;
+use App\Tools\RedisClusters;
+use Illuminate\Support\Facades\Redis;
 
 
 class ExportOffline extends Command
 class ExportOffline extends Command
 {
 {
@@ -66,7 +68,7 @@ class ExportOffline extends Command
         //导出channel
         //导出channel
         $this->info('channel');
         $this->info('channel');
         $this->call('export:channel');
         $this->call('export:channel');
-        
+
         //tag
         //tag
         $this->info('tag');
         $this->info('tag');
         $this->call('export:tag');
         $this->call('export:tag');
@@ -85,7 +87,7 @@ class ExportOffline extends Command
         $this->call('export:sentence',['--type'=>'original']);
         $this->call('export:sentence',['--type'=>'original']);
 
 
         $this->info('zip');
         $this->info('zip');
-        
+
         $exportPath = 'app/public/export/offline';
         $exportPath = 'app/public/export/offline';
         $exportFile = 'wikipali-offline-'.date("Y-m-d").'.db3';
         $exportFile = 'wikipali-offline-'.date("Y-m-d").'.db3';
         Log::debug('zip file {filename} {format}',
         Log::debug('zip file {filename} {format}',
@@ -109,7 +111,6 @@ class ExportOffline extends Command
         $zipFullFileName = storage_path($exportPath.'/'.$zipFile);
         $zipFullFileName = storage_path($exportPath.'/'.$zipFile);
 
 
         shell_exec("cd ".storage_path($exportPath));
         shell_exec("cd ".storage_path($exportPath));
-        shell_exec("chmod 600 {$exportFullFileName}");
         if($this->argument('format')==='7z'){
         if($this->argument('format')==='7z'){
             $command = "7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on {$zipFullFileName} {$exportFullFileName}";
             $command = "7z a -t7z -m0=lzma -mx=9 -mfb=64 -md=32m -ms=on {$zipFullFileName} {$exportFullFileName}";
         }else if($this->argument('format')==='lzma'){
         }else if($this->argument('format')==='lzma'){
@@ -123,13 +124,14 @@ class ExportOffline extends Command
         $info = array();
         $info = array();
         $info[] = ['filename'=>$zipFile,
         $info[] = ['filename'=>$zipFile,
                    'create_at'=>date("Y-m-d H:i:s"),
                    'create_at'=>date("Y-m-d H:i:s"),
-                   'chapter'=>Cache::get("/export/chapter/count"),
+                   'chapter'=>RedisClusters::get("/export/chapter/count"),
                    'filesize'=>filesize($zipFullFileName),
                    'filesize'=>filesize($zipFullFileName),
                    'min_app_ver'=>'1.3',
                    'min_app_ver'=>'1.3',
                     ];
                     ];
-        Cache::put('/offline/index',$info);
+        RedisClusters::put('/offline/index',$info);
         unlink($exportStop);
         unlink($exportStop);
-        Log::debug('zip file {filename} in {format} finished',
+
+        Log::debug('zip file {filename} in {format} saved.',
                     [
                     [
                         'filename'=>$exportFile,
                         'filename'=>$exportFile,
                         'format'=>$this->argument('format')
                         'format'=>$this->argument('format')

+ 10 - 8
app/Console/Commands/UpgradeDaily.php

@@ -43,38 +43,40 @@ class UpgradeDaily extends Command
         if(\App\Tools\Tools::isStop()){
         if(\App\Tools\Tools::isStop()){
             return 0;
             return 0;
         }
         }
-        Log::info('daily task start');
+        $env = config('app.env');
+        Log::info('daily task start ',['app.env'=>$env]);
         $start = time();
         $start = time();
 		if(app()->isLocal()==false){
 		if(app()->isLocal()==false){
+
 			$this->call('message:webhook',[
 			$this->call('message:webhook',[
 				'listener' => 'dingtalk',
 				'listener' => 'dingtalk',
 				'url' => 'dingtalk1',
 				'url' => 'dingtalk1',
 				'title' => "后台任务",
 				'title' => "后台任务",
-				'message' => " wikipali: 每日统计后台任务开始执行。",
+				'message' => " wikipali: 每日统计后台任务开始执行。app.env=".$env,
 			]);
 			]);
 		}
 		}
-        Log::info('wikipali: 每日统计后台任务开始执行');
-        $message = "wikipali: 每日统计后台任务执行完毕。";
+        Log::info('wikipali: 每日统计后台任务开始执行{app.env}',['app.env'=>$env]);
+        $message = "wikipali: 每日统计后台任务执行完毕。".$env;
 
 
         //更新单词首选意思
         //更新单词首选意思
         $this->call('upgrade:dict.default.meaning');
         $this->call('upgrade:dict.default.meaning');
         $time = time()-$start;
         $time = time()-$start;
         $message .= "dict.default.meaning:{$time}; ";
         $message .= "dict.default.meaning:{$time}; ";
         $currTime = time();
         $currTime = time();
-        Log::info('更新单词首选意思完毕');
+        Log::info('更新单词首选意思完毕'.$env);
 
 
         //社区术语表
         //社区术语表
         $this->call('upgrade:community.term',['lang'=>'zh-Hans']);
         $this->call('upgrade:community.term',['lang'=>'zh-Hans']);
         $time = time()-$currTime;
         $time = time()-$currTime;
         $message .= "community.term:{$time}; ";
         $message .= "community.term:{$time}; ";
         $currTime = time();
         $currTime = time();
-        Log::info('社区术语表完毕');
+        Log::info('社区术语表完毕 {app.env}',['app.env'=>$env]);
 
 
         # 导出离线数据
         # 导出离线数据
         $this->call('export:offline',['format'=>'lzma']);
         $this->call('export:offline',['format'=>'lzma']);
         $time = time()-$currTime;
         $time = time()-$currTime;
         $message .= "export:offline:{$time}; ";
         $message .= "export:offline:{$time}; ";
-        Log::info('导出离线数据完毕');
+        Log::info('导出离线数据完毕{app.env}',['app.env'=>$env]);
 
 
         $time = time()-$start;
         $time = time()-$start;
         $message .= "总时间:{$time}; ";
         $message .= "总时间:{$time}; ";
@@ -84,7 +86,7 @@ class UpgradeDaily extends Command
 				'listener' => 'dingtalk',
 				'listener' => 'dingtalk',
 				'url' => 'dingtalk1',
 				'url' => 'dingtalk1',
 				'title' => "后台任务",
 				'title' => "后台任务",
-				'message' => $message,
+				'message' => $message.' app.env='.$env,
 			]);
 			]);
 			//发送dingding消息
 			//发送dingding消息
 			$this->call('message:webhookarticlenew',[
 			$this->call('message:webhookarticlenew',[

+ 67 - 65
app/Http/Controllers/CorpusController.php

@@ -887,7 +887,7 @@ class CorpusController extends Controller
 
 
 		#生成channel 数量列表
 		#生成channel 数量列表
 		$sentId = "{$book}-{$para}-{$word_start}-{$word_end}";
 		$sentId = "{$book}-{$para}-{$word_start}-{$word_end}";
-        $channelCount = CorpusController::sentCanReadCount($book,$para,$word_start,$word_end,$this->userUuid);
+        $channelCount = CorpusController::_sentCanReadCount($book,$para,$word_start,$word_end,$this->userUuid);
         $path = json_decode(PaliText::where('book',$book)->where('paragraph',$para)->value("path"),true);
         $path = json_decode(PaliText::where('book',$book)->where('paragraph',$para)->value("path"),true);
         $sent["path"] = [];
         $sent["path"] = [];
         foreach ($path as $key => $value) {
         foreach ($path as $key => $value) {
@@ -903,12 +903,75 @@ class CorpusController extends Controller
 		return $sent;
 		return $sent;
 	}
 	}
 
 
+    public static function _sentCanReadCount($book,$para,$start,$end,$userUuid=null){
+        $keyCanRead="/channel/can-read/";
+        if($userUuid){
+            $keyCanRead .= $userUuid;
+        }else{
+            $keyCanRead .= 'guest';
+        }
+        $channelCanRead = RedisClusters::remember($keyCanRead,
+                            config('mint.cache.expire'),
+                            function() use($userUuid){
+                                return ChannelApi::getCanReadByUser($userUuid);
+                            });
+        $channels =  Sentence::where('book_id',$book)
+            ->where('paragraph',$para)
+            ->where('word_start',$start)
+            ->where('word_end',$end)
+            ->where('strlen','<>',0)
+            ->whereIn('channel_uid',$channelCanRead)
+            ->select('channel_uid')
+            ->groupBy('channel_uid')
+            ->get();
+        $channelList = [];
+        foreach ($channels as $key => $value) {
+            # code...
+            if(Str::isUuid($value->channel_uid)){
+                $channelList[] = $value->channel_uid;
+            }
+        }
+        $simId = PaliSentence::where('book',$book)
+                            ->where('paragraph',$para)
+                            ->where('word_begin',$start)
+                            ->where('word_end',$end)
+                            ->value('id');
+        if($simId){
+            $output["simNum"]=SentSimIndex::where('sent_id',$simId)->value('count');
+        }else{
+            $output["simNum"]=0;
+        }
+        $channelInfo = Channel::whereIn("uid",$channelList)->select('type')->get();
+        $output["tranNum"]=0;
+        $output["nissayaNum"]=0;
+        $output["commNum"]=0;
+        $output["originNum"]=0;
+
+        foreach ($channelInfo as $key => $value) {
+            # code...
+            switch($value->type){
+                case "translation":
+                    $output["tranNum"]++;
+                    break;
+                case "nissaya":
+                    $output["nissayaNum"]++;
+                    break;
+                case "commentary":
+                    $output["commNum"]++;
+                    break;
+                case "original":
+                    $output["originNum"]++;
+                    break;
+            }
+        }
+        return $output;
+    }
     /**
     /**
      * 获取某个句子的相关资源的句子数量
      * 获取某个句子的相关资源的句子数量
      */
      */
     public static function sentCanReadCount($book,$para,$start,$end,$userUuid=null){
     public static function sentCanReadCount($book,$para,$start,$end,$userUuid=null){
 		$sentId = "{$book}-{$para}-{$start}-{$end}";
 		$sentId = "{$book}-{$para}-{$start}-{$end}";
-        $key = "/sentence/{$sentId}/channels/count";
+        $key = "/sentence/res-count/{$sentId}/";
         if($userUuid){
         if($userUuid){
             $key .= $userUuid;
             $key .= $userUuid;
         }else{
         }else{
@@ -916,69 +979,8 @@ class CorpusController extends Controller
         }
         }
 		$channelCount = RedisClusters::remember($key,config('mint.cache.expire'),
 		$channelCount = RedisClusters::remember($key,config('mint.cache.expire'),
                           function() use($book,$para,$start,$end,$userUuid){
                           function() use($book,$para,$start,$end,$userUuid){
-                            $keyCanRead="/channel/can-read/";
-                            if($userUuid){
-                                $keyCanRead .= $userUuid;
-                            }else{
-                                $keyCanRead .= 'guest';
-                            }
-                            $channelCanRead = RedisClusters::remember($keyCanRead,
-                                                config('mint.cache.expire'),
-                                                function() use($userUuid){
-                                                    return ChannelApi::getCanReadByUser($userUuid);
-                                                });
-			                $channels =  Sentence::where('book_id',$book)
-                                ->where('paragraph',$para)
-                                ->where('word_start',$start)
-                                ->where('word_end',$end)
-                                ->where('strlen','<>',0)
-                                ->whereIn('channel_uid',$channelCanRead)
-                                ->select('channel_uid')
-                                ->groupBy('channel_uid')
-                                ->get();
-            $channelList = [];
-            foreach ($channels as $key => $value) {
-                # code...
-                if(Str::isUuid($value->channel_uid)){
-                    $channelList[] = $value->channel_uid;
-                }
-            }
-            $simId = PaliSentence::where('book',$book)
-                                 ->where('paragraph',$para)
-                                 ->where('word_begin',$start)
-                                 ->where('word_end',$end)
-                                 ->value('id');
-            if($simId){
-                $output["simNum"]=SentSimIndex::where('sent_id',$simId)->value('count');
-            }else{
-                $output["simNum"]=0;
-            }
-            $channelInfo = Channel::whereIn("uid",$channelList)->select('type')->get();
-            $output["tranNum"]=0;
-            $output["nissayaNum"]=0;
-            $output["commNum"]=0;
-            $output["originNum"]=0;
-
-            foreach ($channelInfo as $key => $value) {
-                # code...
-                switch($value->type){
-                    case "translation":
-                        $output["tranNum"]++;
-                        break;
-                    case "nissaya":
-                        $output["nissayaNum"]++;
-                        break;
-                    case "commentary":
-                        $output["commNum"]++;
-                        break;
-                    case "original":
-                        $output["originNum"]++;
-                        break;
-                }
-            }
-			return $output;
-
-		});
+                            return CorpusController::_sentCanReadCount($book,$para,$start,$end,$userUuid);
+		                });
         return $channelCount;
         return $channelCount;
     }
     }
     private function markdownRender($input){
     private function markdownRender($input){

+ 8 - 5
app/Http/Controllers/OfflineIndexController.php

@@ -4,6 +4,9 @@ namespace App\Http\Controllers;
 
 
 use Illuminate\Http\Request;
 use Illuminate\Http\Request;
 use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\Cache;
+use App\Tools\RedisClusters;
+use Illuminate\Support\Facades\Redis;
+use Illuminate\Support\Facades\Log;
 
 
 class OfflineIndexController extends Controller
 class OfflineIndexController extends Controller
 {
 {
@@ -15,8 +18,8 @@ class OfflineIndexController extends Controller
     public function index()
     public function index()
     {
     {
         //
         //
-        if(Cache::has('/offline/index')){
-            return Cache::get('/offline/index');
+        if(RedisClusters::has('/offline/index')){
+            return RedisClusters::get('/offline/index');
         }else{
         }else{
             return [];
             return [];
         }
         }
@@ -36,12 +39,12 @@ class OfflineIndexController extends Controller
     /**
     /**
      * Display the specified resource.
      * Display the specified resource.
      *
      *
-     * @param  int  $id
+     * @param  string  $filename
      * @return \Illuminate\Http\Response
      * @return \Illuminate\Http\Response
      */
      */
-    public function show($id)
+    public function show($filename)
     {
     {
-        //
+
     }
     }
 
 
     /**
     /**