Ver Fonte

vocabulary 不 查询 term

visuddhinanda há 2 anos atrás
pai
commit
ee7df80038

+ 15 - 1
app/Http/Controllers/RelationController.php

@@ -9,6 +9,7 @@ use App\Http\Api\AuthApi;
 use Illuminate\Support\Facades\App;
 use PhpOffice\PhpSpreadsheet\Spreadsheet;
 use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
+use Illuminate\Support\Facades\Cache;
 
 class RelationController extends Controller
 {
@@ -20,6 +21,12 @@ class RelationController extends Controller
     public function index(Request $request)
     {
         //
+        $key = 'relation-vocabulary';
+        if($request->has('vocabulary')){
+            if(Cache::has($key)){
+                return $this->ok(Cache::get($key));
+            }
+        }
         $table = Relation::select(['id','name','case','from','to',
                                     'category','editor_id','match',
                                     'updated_at','created_at']);
@@ -51,7 +58,14 @@ class RelationController extends Controller
                        ->take($request->get('limit',1000));
         $result = $table->get();
 
-        return $this->ok(["rows"=>RelationResource::collection($result),"count"=>$count]);
+        $output = ["rows"=>RelationResource::collection($result),"count"=>$count];
+
+        if($request->has('vocabulary')){
+            if(!Cache::has($key)){
+                Cache::put($key,$output,env('CACHE_EXPIRE',3600*24));
+            }
+        }
+        return $this->ok($output);
     }
 
 

+ 33 - 26
app/Http/Resources/RelationResource.php

@@ -25,39 +25,46 @@ class RelationResource extends JsonResource
             "to"=> json_decode($this->to),
             "match"=> json_decode($this->match),
             "category"=> $this->category,
-            "editor"=> UserApi::getByUuid($this->editor_id),
             "created_at"=> $this->created_at,
             "updated_at"=> $this->updated_at,
         ];
-        $lang = $request->get('ui-lang');
-        //TODO 默认英文
-        $uiLang = strtolower($request->get('ui-lang','zh-Hans')) ;
-        $term_channel = ChannelApi::getSysChannel("_System_Grammar_Term_{$uiLang}_");
-        if($term_channel){
-            $data['category_channel'] = $term_channel;
-            if(!empty($this->category)){
-                $term = DhammaTerm::where("word",$this->category)
-                                            ->where('channal',$term_channel)
-                                            ->first();
-                if($term){
-                    $data['category_term']['channelId'] = $term_channel;
-                    $data['category_term']['word'] = $term->word;
-                    $data['category_term']['id'] = $term->guid;
-                    $data['category_term']['meaning'] = $term->meaning;
+
+
+        if(!$request->has('vocabulary')){
+            //TODO 默认英文
+            $data["editor"] = UserApi::getByUuid($this->editor_id);
+            $lang = $request->get('ui-lang');
+
+            $uiLang = strtolower($request->get('ui-lang','zh-Hans')) ;
+            $term_channel = ChannelApi::getSysChannel("_System_Grammar_Term_{$uiLang}_");
+            if($term_channel){
+                $data['category_channel'] = $term_channel;
+                if(!empty($this->category)){
+                    $term = DhammaTerm::where("word",$this->category)
+                                                ->where('channal',$term_channel)
+                                                ->first();
+                    if($term){
+                        $data['category_term']['channelId'] = $term_channel;
+                        $data['category_term']['word'] = $term->word;
+                        $data['category_term']['id'] = $term->guid;
+                        $data['category_term']['meaning'] = $term->meaning;
+                    }
+                }
+                $data['name_channel'] = $term_channel;
+                $term_name = DhammaTerm::where("word",$this->name)
+                    ->where('channal',$term_channel)
+                    ->first();
+                if($term_name){
+                    $data['name_term']['channelId'] = $term_channel;
+                    $data['name_term']['word'] = $term_name->word;
+                    $data['name_term']['id'] = $term_name->guid;
+                    $data['name_term']['meaning'] = $term_name->meaning;
                 }
-            }
-            $data['name_channel'] = $term_channel;
-            $term_name = DhammaTerm::where("word",$this->name)
-                ->where('channal',$term_channel)
-                ->first();
-            if($term_name){
-                $data['name_term']['channelId'] = $term_channel;
-                $data['name_term']['word'] = $term_name->word;
-                $data['name_term']['id'] = $term_name->guid;
-                $data['name_term']['meaning'] = $term_name->meaning;
             }
         }
+        /*
 
+*/
 
         return $data;
     }