Переглянути джерело

Merge pull request #2444 from visuddhinanda/development

预渲染内容存redis
visuddhinanda 1 тиждень тому
батько
коміт
f55dd1c241

+ 5 - 1
api-v13/app/Console/Commands/IndexTipitaka.php

@@ -13,6 +13,8 @@ use App\Services\SummaryService;
 use App\Services\TagService;
 use App\Services\TagService;
 use Illuminate\Console\Command;
 use Illuminate\Console\Command;
 use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Log;
+use Illuminate\Support\Facades\Cache;
+
 
 
 class IndexTipitaka extends Command
 class IndexTipitaka extends Command
 {
 {
@@ -403,8 +405,9 @@ class IndexTipitaka extends Command
             ->where('channel_id', $param['channel'])
             ->where('channel_id', $param['channel'])
             ->first();
             ->first();
         $channel = ChannelApi::getById($param['channel']);
         $channel = ChannelApi::getById($param['channel']);
+        $docId = "tipitaka_chapter_{$param['book']}-{$param['para']}_{$param['channel']}";
         $document = [
         $document = [
-            'id' => "tipitaka_chapter_{$param['book']}-{$param['para']}_{$param['channel']}",
+            'id' => $docId,
             'resource_id' => $progress ? $progress->uid : "{$param['book']}-{$param['para']}_{$param['channel']}",
             'resource_id' => $progress ? $progress->uid : "{$param['book']}-{$param['para']}_{$param['channel']}",
             'resource_type' => 'tipitaka',
             'resource_type' => 'tipitaka',
             'title' => [],
             'title' => [],
@@ -430,6 +433,7 @@ class IndexTipitaka extends Command
             $document['title']['text']['pali'] = $title;
             $document['title']['text']['pali'] = $title;
         }
         }
         $document['content']['display'] = $param['content'];             // 展示
         $document['content']['display'] = $param['content'];             // 展示
+        Cache::put($docId,$param['content']);
 
 
         if ($this->isTest) {
         if ($this->isTest) {
             $this->info($param['content']);
             $this->info($param['content']);

+ 14 - 7
api-v13/app/Http/Controllers/Library/BookController.php

@@ -2,6 +2,8 @@
 
 
 namespace App\Http\Controllers\Library;
 namespace App\Http\Controllers\Library;
 
 
+use Illuminate\Support\Facades\Cache;
+
 use App\DTO\Search\HitItemDTO;
 use App\DTO\Search\HitItemDTO;
 use App\Http\Api\ChannelApi;
 use App\Http\Api\ChannelApi;
 use App\Http\Api\StudioApi;
 use App\Http\Api\StudioApi;
@@ -16,6 +18,7 @@ use Illuminate\Http\Request;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Collection;
 use Illuminate\Support\Facades\Log;
 use Illuminate\Support\Facades\Log;
 
 
+
 class BookController extends Controller
 class BookController extends Controller
 {
 {
     /**
     /**
@@ -241,13 +244,17 @@ class BookController extends Controller
         foreach ($chapters as $chapter) {
         foreach ($chapters as $chapter) {
             $openSearchId = "tipitaka_chapter_{$book}-{$chapter->paragraph}_{$channelId}";
             $openSearchId = "tipitaka_chapter_{$book}-{$chapter->paragraph}_{$channelId}";
 
 
-            try {
-                $doc = HitItemDTO::fromArray($this->searchService->get($openSearchId))->toArray();
-            } catch (\Throwable $th) {
-                continue;
-            }
-
-            $display .= $doc['display'] ?? '';
+            $conntent = Cache::rememberForever($openSearchId, function () use($openSearchId) {
+                            //Log::debug($openSearchId.' not hit');
+                            $doc = [];
+                            try {
+                                $doc = HitItemDTO::fromArray($this->searchService->get($openSearchId))->toArray();
+                            } catch (\Throwable $th) {
+                            }
+                            return $doc['display'] ?? '';
+                        });
+            
+            $display .= $conntent;
 
 
             if ("{$book}-{$chapter->paragraph}" === $selectedId) {
             if ("{$book}-{$chapter->paragraph}" === $selectedId) {
                 $title = $doc['title'] ?? '';
                 $title = $doc['title'] ?? '';