visuddhinanda 2 anni fa
parent
commit
a5626a3d94

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

@@ -5,6 +5,7 @@ namespace App\Console\Commands;
 use Illuminate\Console\Command;
 use App\Http\Api\DictApi;
 use App\Models\UserDict;
+use Illuminate\Support\Facades\Redis;
 
 class ExportFtsPali extends Command
 {
@@ -55,7 +56,8 @@ class ExportFtsPali extends Command
 
         $pageSize = 10000;
         $currPage = 1;
-        $fp = fopen($path."/pali-{$currPage}.syn",'w') or die("Unable to open file!");
+        $filename = "/pali-{$currPage}.syn";
+        $fp = fopen($path.$filename,'w') or die("Unable to open file!");
         $count = 0;
         foreach ($dictId as $key => $value) {
             $words = UserDict::where('dict_id',$value)
@@ -69,6 +71,10 @@ class ExportFtsPali extends Command
                 }
                 if($count % 10000 === 0){
                     fclose($fp);
+                    $redisKey = 'export/fts/pali'.$filename;
+                    $content = file_get_contents($path.$filename);
+                    Redis::set($redisKey,$content);
+                    Redis::expire($redisKey,3600*24*10);
                     $currPage++;
                     $filename = "/pali-{$currPage}.syn";
                     $this->info('new file filename='.$filename);

+ 4 - 4
app/Http/Controllers/PgPaliDictDownloadController.php

@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
 
 use App\Models\UserDict;
 use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Redis;
 
 class PgPaliDictDownloadController extends Controller
 {
@@ -15,15 +16,14 @@ class PgPaliDictDownloadController extends Controller
     public function index(Request $request)
     {
         $currPage = $request->get('page',1);
-        $path = storage_path('app/export/fts');
+        $path = 'export/fts/pali';
         $filename = $path."/pali-{$currPage}.syn";
-        if(file_exists($filename)){
-            $content = file_get_contents($filename);
+        if(Redis::exists($filename)){
+            $content = Redis::get($filename);
             return $this->ok($content);
         }else{
             return $this->error('no file',200,200);
         }
-
     }
 
     /**