Преглед изворни кода

env('CACHE_EXPIRE',3600*24)

visuddhinanda пре 2 година
родитељ
комит
7375c57a9f

+ 1 - 1
app/Console/Commands/UpgradeDict.php

@@ -122,7 +122,7 @@ class UpgradeDict extends Command
 														if(isset($newPart[$part])){
 															$newPart[$part][0]++;
 														}else{
-															$partExists = Cache::remember('dict/part/'.$part,1000,function() use($part){
+															$partExists = Cache::remember('dict/part/'.$part,env('CACHE_EXPIRE',1000),function() use($part){
 																return UserDict::where('word',$part)->exists();
 															});
 															if(!$partExists){

+ 15 - 13
app/Http/Controllers/CorpusController.php

@@ -572,14 +572,16 @@ class CorpusController extends Controller
 
                             break;
                         case 'nissaya':
-                            $newSent['html'] = Cache::remember("/sent/{$channelId}/{$currSentId}",10,
-                            function() use($row,$mode){
-                                return MdRender::render($row->content,$row->channel_uid,null,$mode,"nissaya",$row->content_type);
-                            });
+                            $newSent['html'] = Cache::remember("/sent/{$channelId}/{$currSentId}",
+                                                env('CACHE_EXPIRE',3600*24),
+                                                function() use($row,$mode){
+                                                    return MdRender::render($row->content,$row->channel_uid,null,$mode,"nissaya",$row->content_type);
+                                                });
                             break;
                         default:
                             //译文需要markdown渲染
-                            $newSent['html'] = Cache::remember("/sent/{$channelId}/{$currSentId}",10,
+                            $newSent['html'] = Cache::remember("/sent/{$channelId}/{$currSentId}",
+                                                env('CACHE_EXPIRE',3600*24),
                                                 function() use($row){
                                                     return MdRender::render($row->content,$row->channel_uid);
                                                 });
@@ -807,15 +809,15 @@ class CorpusController extends Controller
     public static function sentResCount($book,$para,$start,$end){
 		$sentId = "{$book}-{$para}-{$start}-{$end}";
 		$channelCount = Cache::remember("/sentence/{$sentId}/channels/count",
-                          60,
+                          env('CACHE_EXPIRE',3600*24),
                           function() use($book,$para,$start,$end){
-			$channels =  Sentence::where('book_id',$book)
-							->where('paragraph',$para)
-							->where('word_start',$start)
-							->where('word_end',$end)
-							->select('channel_uid')
-                            ->groupBy('channel_uid')
-							->get();
+			                $channels =  Sentence::where('book_id',$book)
+                                ->where('paragraph',$para)
+                                ->where('word_start',$start)
+                                ->where('word_end',$end)
+                                ->select('channel_uid')
+                                ->groupBy('channel_uid')
+                                ->get();
             $channelList = [];
             foreach ($channels as $key => $value) {
                 # code...

+ 23 - 21
app/Http/Controllers/SentenceInfoController.php

@@ -56,10 +56,10 @@ class SentenceInfoController extends Controller
 
 
         #默认完成度显示字符数
-        # strlen 
+        # strlen
         # palistrlen 巴利语等效字符数
         # page
-        # percent 
+        # percent
         $view = 'strlen';
         if($request->has('view')){
             $view =$request->get('view');
@@ -122,18 +122,20 @@ class SentenceInfoController extends Controller
             $allStrLen = PaliSentence::where('book',$request->get('book'))
                             ->where('paragraph','>=',$request->get('from'))
                             ->where('paragraph','<=',$to)
-                            ->sum('length');            
+                            ->sum('length');
             $para_strlen = 0;
-            
+
             foreach ($sentFinished as $sent) {
                 # code...
 				$key_sent_id = $sent->book_id.'-'.$sent->paragraph.'-'.$sent->word_start.'-'.$sent->word_end;
-				$para_strlen += Cache::remember('pali-sent/strlen/'.$key_sent_id, 6000000 , function() use($sent) {
-					return PaliSentence::where('book',$sent->book_id)
-							->where('paragraph',$sent->paragraph)
-							->where('word_begin',$sent->word_start)
-							->where('word_end',$sent->word_end)
-							->value('length');
+				$para_strlen += Cache::remember('pali-sent/strlen/'.$key_sent_id,
+                                    env('CACHE_EXPIRE',3600*24*30) ,
+                                    function() use($sent) {
+                                        return PaliSentence::where('book',$sent->book_id)
+                                                ->where('paragraph',$sent->paragraph)
+                                                ->where('word_begin',$sent->word_start)
+                                                ->where('word_end',$sent->word_end)
+                                                ->value('length');
 				});
             }
 
@@ -215,9 +217,9 @@ class SentenceInfoController extends Controller
         $yMin = 20; //y轴满刻度数值 最小
 
         #默认完成度显示字符数
-        # strlen 
+        # strlen
         # page
-        # percent 
+        # percent
         $view = 'strlen';
         if($request->has('view')){
             $view =$request->get('view');
@@ -226,7 +228,7 @@ class SentenceInfoController extends Controller
             $view =$request->get('type');
         }
 
-        
+
 
         $pagePix = ($imgHeight-$xAxisOffset)/$maxPage;
         $dayPix = ($imgWidth-$yAxisOffset)/$maxDay;
@@ -266,12 +268,12 @@ class SentenceInfoController extends Controller
                 $max = $current;
             }
         }
-        /* 
+        /*
         * 计算Y 轴满刻度值
         * 算法 不足 20 按 20 算 小于100 满刻度是是50的整倍数
         * 小于1000 满刻度是是500的整倍数
         */
-        
+
         if($max < $yMin){
             $yMax = $yMin;
         }else{
@@ -286,14 +288,14 @@ class SentenceInfoController extends Controller
         $rate = $yPix / $yMax;
 
         $svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" fill=\"currentColor\" class=\"bi bi-alarm-fill\" viewBox=\"0 0 $imgWidth $imgHeight\">";
-        
+
         //绘制坐标轴
         imageline($img,0,$imgHeight-$xAxisOffset,$imgWidth,$imgHeight-$xAxisOffset,$color);
         imageline($img,$yAxisOffset,$imgHeight,$yAxisOffset,0,$color);
-        // x 轴 
+        // x 轴
         $y=$imgHeight-$xAxisOffset+1;
         $svg .= "<line x1='$yAxisOffset'  y1='$y' x2='$imgWidth'   y2='$y' style='stroke:#666666;'></line>";
-        // y 轴 
+        // y 轴
         $x = $yAxisOffset - 1;
         $svg .= "<line x1='$x'  y1='0' x2='$x'   y2='".($imgHeight-$xAxisOffset)."' style='stroke:#666666;'></line>";
         //绘制x轴刻度线
@@ -311,11 +313,11 @@ class SentenceInfoController extends Controller
             $svg .= "<line x1='$x'  y1='$y' x2='$x'   y2='".($y+$height)."' style='stroke:#666666;'></line>";
             $svg .= "<text x='".($x-5)."' y='".($y+12)."' style='font-size:8px;'>$day</text>";
         }
-        
-        
+
+
         //绘制y轴刻度线 将y轴五等分
         $step = $yMax / 5 * $rate;
-        for ($i=1; $i < 5; $i++) { 
+        for ($i=1; $i < 5; $i++) {
             # code...
             $yValue = $yMax / 5 * $i;
             if($yValue>=1000000){

+ 1 - 1
app/Http/Controllers/UserStatisticController.php

@@ -57,7 +57,7 @@ class UserStatisticController extends Controller
         //
         $queryUserId = UserApi::getIntIdByName($userName);
         $queryUserUuid = UserApi::getIdByName($userName);
-        $cacheExpiry = 600;
+        $cacheExpiry = env('CACHE_EXPIRE',3600*24);
         //总经验值
         $expSum = Cache::remember("user/{$userName}/exp/sum",$cacheExpiry,function() use($queryUserId){
 			return UserOperationDaily::where('user_id',$queryUserId)

+ 3 - 1
app/Http/Controllers/VocabularyController.php

@@ -21,7 +21,9 @@ class VocabularyController extends Controller
         switch ($request->get("view")) {
             case 'key':
                 $key = $request->get("key");
-                $result = Cache::remember("/dict_vocabulary/{$key}",10,function() use($key){
+                $result = Cache::remember("/dict_vocabulary/{$key}",
+                        env('CACHE_EXPIRE',3600*24),
+                        function() use($key){
                         return Vocabulary::whereRaw('word like ? or word_en like ?',[$key."%",$key."%"])
                                     ->whereOr('word_en','like',$key."%")
                                     ->orderBy('strlen')

+ 24 - 16
app/Tools/TurboSplit.php

@@ -176,9 +176,11 @@ class TurboSplit
         $search = $word;
 
 		//获取单词权重
-		$row = Cache::remember('palicanon/wordpart/weight/'.$search, 10 , function() use($search) {
-			return WordPart::where('word',$search)->value('weight');
-		});
+		$row = Cache::remember('palicanon/wordpart/weight/'.$search,
+                env('CACHE_EXPIRE',3600*24) ,
+                function() use($search) {
+                    return WordPart::where('word',$search)->value('weight');
+                });
 		if ($row) {
 			//找到
 			return array($row,0);
@@ -202,9 +204,11 @@ class TurboSplit
 			$base_weight = 0;
 			$len = 0;
 			foreach ($newWord as $x => $x_value) {
-				$row = Cache::remember('palicanon/wordpart/weight/'.$search, 10 , function() use($x) {
-					return WordPart::where('word',$x)->value('weight');
-				});
+				$row = Cache::remember('palicanon/wordpart/weight/'.$search,
+                        env('CACHE_EXPIRE',3600*24) ,
+                        function() use($x) {
+                            return WordPart::where('word',$x)->value('weight');
+                        });
 				if ($row) {
 					if ($row > $base_weight) {
 						$base_weight = $row;
@@ -230,9 +234,11 @@ class TurboSplit
 
 		$isFound = false;
 		$count = 0;
-		$wordPart  = Cache::remember("turbosplit/part/{$word}",10,function() use($word){
-			return implode(',',$this->dict_lookup($word));
-		});
+		$wordPart  = Cache::remember("turbosplit/part/{$word}",
+                        env('CACHE_EXPIRE',3600*24),
+                        function() use($word){
+                            return implode(',',$this->dict_lookup($word));
+                        });
 		$arrWordPart = explode(',',$wordPart);
 		$word_count = $arrWordPart[0];
 		$case_len = $arrWordPart[1];
@@ -244,13 +250,15 @@ class TurboSplit
 
 		//fomular of confidence value 信心值计算公式
 		if ($isFound) {
-			$cf  = Cache::remember("turbosplit/confidence/".$word,1000,function() use($word,$count,$case_len){
-				$len = mb_strlen($word, "UTF-8") - $case_len;
-				$len_correct = 1.2;
-				$count2 = 1.1 + pow($count, 1.18);
-				$conf_num = pow(1 / $count2, pow(($len - 0.5), $len_correct));
-				return round(1 / (1 + 640 * $conf_num), 9);
-			});
+			$cf  = Cache::remember("turbosplit/confidence/".$word,
+                    env('CACHE_EXPIRE',1000),
+                    function() use($word,$count,$case_len){
+                        $len = mb_strlen($word, "UTF-8") - $case_len;
+                        $len_correct = 1.2;
+                        $count2 = 1.1 + pow($count, 1.18);
+                        $conf_num = pow(1 / $count2, pow(($len - 0.5), $len_correct));
+                        return round(1 / (1 + 640 * $conf_num), 9);
+                    });
 			return ($cf);
 		} else {
 			return (-1);