Browse Source

修正php8下定时任务问题、优化搜索缓存、搜索缓存默认关闭

magicblack 3 years ago
parent
commit
848f216071

+ 0 - 4
application/admin/controller/System.php

@@ -153,10 +153,6 @@ class System extends Base
         if (!isset($config['app']['input_type'])) {
             $config['app']['input_type'] = 1;
         }
-        // 视频搜索优化,默认frontend
-        if (!isset($config['app']['vod_search_optimise'])) {
-            $config['app']['vod_search_optimise'] = 'frontend';
-        }
         $this->assign('config', $config);
         $this->assign('title', lang('admin/system/config/title'));
         return $this->fetch('admin@system/config');

+ 11 - 9
application/common/model/Collect.php

@@ -4,6 +4,7 @@ use think\Db;
 use think\Cache;
 use app\common\util\Pinyin;
 use think\Request;
+use app\common\validate\Vod as VodValidate;
 
 class Collect extends Base {
 
@@ -167,7 +168,7 @@ class Collect extends Base {
         }
         $html = mac_curl_get($url);
         if(empty($html)){
-            return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err')];
+            return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
         }
         $html = mac_filter_tags($html);
         $xml = @simplexml_load_string($html);
@@ -423,6 +424,7 @@ class Collect extends Base {
         $downers = config('voddowner');
         $vod_search = model('VodSearch');
         $vod_search_enabled = $vod_search->isCollectEnabled();
+        $vs_max_id_count = $vod_search->maxIdCount;
 
         $type_list = model('Type')->getCache('type_list');
         $filter_arr = explode(',',$config['filter']);
@@ -585,7 +587,7 @@ class Collect extends Base {
                     ];
                     // 结果太大时,筛选更耗时。仅在结果数量较小时,才加入
                     $GLOBALS['blend']['vod_id'] = null;
-                    if ($vod_search_enabled && count($search_actor_id_list) < 1000) {
+                    if ($vod_search_enabled && count($search_actor_id_list) <= $vs_max_id_count) {
                         $GLOBALS['blend']['vod_id'] = ['IN', $search_actor_id_list];
                     }
                     unset($where['vod_actor'],$where['vod_director']);
@@ -712,7 +714,7 @@ class Collect extends Base {
                         $tmp = $this->syncImages($config_sync_pic,  $v['vod_pic'], 'vod');
                         $v['vod_pic'] = mac_filter_xss((string)$tmp['pic']);
                         $msg = $tmp['msg'];
-                        $v = model('Vod')->formatDataBeforeDb($v);
+                        $v = VodValidate::formatDataBeforeDb($v);
                         $vod_id = model('Vod')->insert($v, false, true);
                         if ($vod_id > 0) {
                             $vod_search_enabled && $vod_search->checkAndUpdateTopResults(['vod_id' => $vod_id] + $v, true);
@@ -939,7 +941,7 @@ class Collect extends Base {
                             $update['vod_time'] = time();
                             $where = [];
                             $where['vod_id'] = $info['vod_id'];
-                            $update = model('Vod')->formatDataBeforeDb($update);
+                            $update = VodValidate::formatDataBeforeDb($update);
                             $res = model('Vod')->where($where)->update($update);
                             $color = 'green';
                             if ($res === false) {
@@ -1038,7 +1040,7 @@ class Collect extends Base {
         }
         $html = mac_curl_get($url);
         if(empty($html)){
-            return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err')];
+            return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
         }
         $html = mac_filter_tags($html);
         $json = json_decode($html,true);
@@ -1365,7 +1367,7 @@ class Collect extends Base {
         }
         $html = mac_curl_get($url);
         if(empty($html)){
-            return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err')];
+            return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
         }
         $html = mac_filter_tags($html);
         $json = json_decode($html,true);
@@ -1657,7 +1659,7 @@ class Collect extends Base {
         }
         $html = mac_curl_get($url);
         if(empty($html)){
-            return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err')];
+            return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
         }
         $html = mac_filter_tags($html);
         $json = json_decode($html,true);
@@ -1956,7 +1958,7 @@ class Collect extends Base {
         }
         $html = mac_curl_get($url);
         if(empty($html)){
-            return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err')];
+            return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
         }
         $html = mac_filter_tags($html);
         $json = json_decode($html,true);
@@ -2246,7 +2248,7 @@ class Collect extends Base {
         }
         $html = mac_curl_get($url);
         if(empty($html)){
-            return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err')];
+            return ['code'=>1001, 'msg'=>lang('model/collect/get_html_err') . ', url: ' . $url];
         }
         $html = mac_filter_tags($html);
         $json = json_decode($html,true);

+ 33 - 67
application/common/model/Vod.php

@@ -3,6 +3,7 @@ namespace app\common\model;
 use think\Db;
 use think\Cache;
 use app\common\util\Pinyin;
+use app\common\validate\Vod as VodValidate;
 
 class Vod extends Base {
     // 设置数据表(不含前缀)
@@ -400,6 +401,7 @@ class Vod extends Base {
 
         $vod_search = model('VodSearch');
         $vod_search_enabled = $vod_search->isFrontendEnabled();
+        $max_id_count = $vod_search->maxIdCount;
         if ($vod_search_enabled) {
             // 开启搜索优化,查询并缓存Id
             $search_id_list = [];
@@ -408,22 +410,46 @@ class Vod extends Base {
                 if(!empty($GLOBALS['config']['app']['search_vod_rule'])){
                     $role .= '|'.$GLOBALS['config']['app']['search_vod_rule'];
                 }
-                $search_id_list += $vod_search->getResultIdList($wd, $role);
+                $where[$role] = ['like', '%' . $wd . '%'];
+                if (count($search_id_list_tmp = $vod_search->getResultIdList($wd, $role)) <= $max_id_count) {
+                    $search_id_list += $search_id_list_tmp;
+                    unset($where[$role]);
+                }
             }
             if(!empty($name)) {
-                $search_id_list += $vod_search->getResultIdList($name, 'vod_name');
+                $where['vod_name'] = ['like',mac_like_arr($name),'OR'];
+                if (count($search_id_list_tmp = $vod_search->getResultIdList($name, 'vod_name')) <= $max_id_count) {
+                    $search_id_list += $search_id_list_tmp;
+                    unset($where['vod_name']);
+                }
             }
             if(!empty($tag)) {
-                $search_id_list += $vod_search->getResultIdList($tag, 'vod_tag', true);
+                $where['vod_tag'] = ['like',mac_like_arr($tag),'OR'];
+                if (count($search_id_list_tmp = $vod_search->getResultIdList($tag, 'vod_tag', true)) <= $max_id_count) {
+                    $search_id_list += $search_id_list_tmp;
+                    unset($where['vod_tag']);
+                }
             }
             if(!empty($class)) {
-                $search_id_list += $vod_search->getResultIdList($class, 'vod_class', true);
+                $where['vod_class'] = ['like',mac_like_arr($class), 'OR'];
+                if (count($search_id_list_tmp = $vod_search->getResultIdList($class, 'vod_class', true)) <= $max_id_count) {
+                    $search_id_list += $search_id_list_tmp;
+                    unset($where['vod_class']);
+                }
             }
             if(!empty($actor)) {
-                $search_id_list += $vod_search->getResultIdList($actor, 'vod_actor', true);
+                $where['vod_actor'] = ['like', mac_like_arr($actor), 'OR'];
+                if (count($search_id_list_tmp = $vod_search->getResultIdList($actor, 'vod_actor', true)) <= $max_id_count) {
+                    $search_id_list += $search_id_list_tmp;
+                    unset($where['vod_actor']);
+                }
             }
             if(!empty($director)) {
-                $search_id_list += $vod_search->getResultIdList($director, 'vod_director', true);
+                $where['vod_director'] = ['like',mac_like_arr($director),'OR'];
+                if (count($search_id_list_tmp = $vod_search->getResultIdList($director, 'vod_director', true)) <= $max_id_count) {
+                    $search_id_list += $search_id_list_tmp;
+                    unset($where['vod_director']);
+                }
             }
             $search_id_list = array_unique($search_id_list);
             if (!empty($search_id_list)) {
@@ -654,7 +680,7 @@ class Vod extends Base {
         unset($data['uptime']);
         unset($data['uptag']);
 
-        $data = $this->formatDataBeforeDb($data);
+        $data = VodValidate::formatDataBeforeDb($data);
         if(!empty($data['vod_id'])){
             $where=[];
             $where['vod_id'] = ['eq',$data['vod_id']];
@@ -677,66 +703,6 @@ class Vod extends Base {
         return ['code'=>1,'msg'=>lang('save_ok')];
     }
 
-    // xss过滤、长度裁剪
-    public function formatDataBeforeDb($data)
-    {
-        $filter_fields = [
-            'vod_name'         => 255,
-            'vod_sub'          => 255,
-            'vod_en'           => 255,
-            'vod_color'        => 6,
-            'vod_tag'          => 100,
-            'vod_class'        => 255,
-            'vod_pic'          => 1024,
-            'vod_pic_thumb'    => 1024,
-            'vod_pic_slide'    => 1024,
-            'vod_actor'        => 255,
-            'vod_director'     => 255,
-            'vod_writer'       => 100,
-            'vod_behind'       => 100,
-            'vod_blurb'        => 255,
-            'vod_remarks'      => 100,
-            'vod_pubdate'      => 100,
-            'vod_serial'       => 20,
-            'vod_tv'           => 30,
-            'vod_weekday'      => 30,
-            'vod_area'         => 20,
-            'vod_lang'         => 10,
-            'vod_year'         => 10,
-            'vod_version'      => 30,
-            'vod_state'        => 30,
-            'vod_author'       => 60,
-            'vod_jumpurl'      => 150,
-            'vod_tpl'          => 30,
-            'vod_tpl_play'     => 30,
-            'vod_tpl_down'     => 30,
-            'vod_duration'     => 10,
-            'vod_reurl'        => 255,
-            'vod_rel_vod'      => 255,
-            'vod_rel_art'      => 255,
-            'vod_pwd'          => 10,
-            'vod_pwd_url'      => 255,
-            'vod_pwd_play'     => 10,
-            'vod_pwd_play_url' => 255,
-            'vod_pwd_down'     => 10,
-            'vod_pwd_down_url' => 255,
-            'vod_play_from'    => 255,
-            'vod_play_server'  => 255,
-            'vod_play_note'    => 255,
-            'vod_down_from'    => 255,
-            'vod_down_server'  => 255,
-            'vod_down_note'    => 255,
-        ];
-        foreach ($filter_fields as $filter_field => $field_length) {
-            if (!isset($data[$filter_field])) {
-                continue;
-            }
-            $data[$filter_field] = mac_filter_xss($data[$filter_field]);
-            $data[$filter_field] = mb_substr($data[$filter_field], 0, $field_length);
-        }
-        return $data;
-    }
-
     public function savePlot($data)
     {
         $validate = \think\Loader::validate('Vod');

+ 5 - 2
application/common/model/VodSearch.php

@@ -7,9 +7,12 @@ use think\Cache;
 class VodSearch extends Base {
     // 设置数据表(不含前缀)
     protected $name = 'vod_search';
+    // 最大Id数量,使用IN查询时,超过一定数量,查询不使用索引了
+    public $maxIdCount = 1000;
     private $resultCacheDays = 14;
     private $updateTopCount  = 50000;
 
+
     /**
      * 获取结果Id列表
      */
@@ -67,9 +70,9 @@ class VodSearch extends Base {
     public function isFrontendEnabled()
     {
         $config = config('maccms');
-        // 未设置时,默认打开
+        // 未设置时,默认关闭
         if (!isset($config['app']['vod_search_optimise'])) {
-            return true;
+            return false;
         }
         $list = explode('|', $config['app']['vod_search_optimise']);
         return in_array('frontend', $list);

+ 61 - 0
application/common/validate/Vod.php

@@ -19,4 +19,65 @@ class Vod extends Validate
         'edit'  =>  ['vod_name','type_id'],
     ];
 
+
+    // xss过滤、长度裁剪
+    public static function formatDataBeforeDb($data)
+    {
+        $filter_fields = [
+            'vod_name'         => 255,
+            'vod_sub'          => 255,
+            'vod_en'           => 255,
+            'vod_color'        => 6,
+            'vod_tag'          => 100,
+            'vod_class'        => 255,
+            'vod_pic'          => 1024,
+            'vod_pic_thumb'    => 1024,
+            'vod_pic_slide'    => 1024,
+            'vod_actor'        => 255,
+            'vod_director'     => 255,
+            'vod_writer'       => 100,
+            'vod_behind'       => 100,
+            'vod_blurb'        => 255,
+            'vod_remarks'      => 100,
+            'vod_pubdate'      => 100,
+            'vod_serial'       => 20,
+            'vod_tv'           => 30,
+            'vod_weekday'      => 30,
+            'vod_area'         => 20,
+            'vod_lang'         => 10,
+            'vod_year'         => 10,
+            'vod_version'      => 30,
+            'vod_state'        => 30,
+            'vod_author'       => 60,
+            'vod_jumpurl'      => 150,
+            'vod_tpl'          => 30,
+            'vod_tpl_play'     => 30,
+            'vod_tpl_down'     => 30,
+            'vod_duration'     => 10,
+            'vod_reurl'        => 255,
+            'vod_rel_vod'      => 255,
+            'vod_rel_art'      => 255,
+            'vod_pwd'          => 10,
+            'vod_pwd_url'      => 255,
+            'vod_pwd_play'     => 10,
+            'vod_pwd_play_url' => 255,
+            'vod_pwd_down'     => 10,
+            'vod_pwd_down_url' => 255,
+            'vod_play_from'    => 255,
+            'vod_play_server'  => 255,
+            'vod_play_note'    => 255,
+            'vod_down_from'    => 255,
+            'vod_down_server'  => 255,
+            'vod_down_note'    => 255,
+        ];
+        foreach ($filter_fields as $field => $length) {
+            if (!isset($data[$field])) {
+                continue;
+            }
+            $data[$field] = mac_filter_xss($data[$field]);
+            $data[$field] = mb_substr($data[$field], 0, $length);
+        }
+        return $data;
+    }
+
 }

+ 3 - 3
application/lang/zh-cn.php

@@ -694,7 +694,7 @@ https://www.baidu.com/123.jpg
     'model/user/visit_tip'=>'每日仅能获取%s次推广访问积分',
     'model/user/visit_err'=>'插入推广记录失败,请重试',
     'model/user/visit_ok'=>'推广成功',
-    'model/user/reward_tip'=>'用户【%s、%s】消费%S积分,获得奖励%s积分',
+    'model/user/reward_tip'=>'用户【%s、%s】消费%s积分,获得奖励%s积分',
     'model/user/reward_ok'=>'分销提成成功',
 
     'model/website/refer_max'=> '每日仅能%s次来路记录',
@@ -1921,8 +1921,8 @@ https://www.baidu.com/123.jpg
     'api/require_comment_name'=>'评论昵称须err',
     'api/require_comment_name'=>'评论内容必须err',
     'api/never'=>'从未',
-    'api/task_tip_exec'=>'任务:%s,状态:%s,上次执行时间:%S---执行',
-    'api/task_tip_jump'=>'任务:%s,状态:%s,上次执行时间:%S---跳过',
+    'api/task_tip_exec'=>'任务:%s,状态:%s,上次执行时间:%s---执行',
+    'api/task_tip_jump'=>'任务:%s,状态:%s,上次执行时间:%s---跳过',
 
 
     'install/title'=>'苹果CMS-V10系统安装',

+ 3 - 3
application/lang/zh-tw.php

@@ -694,7 +694,7 @@ https://www.baidu.com/123.jpg
     'model/user/visit_tip'=>'每日僅能獲取%s次推廣訪問積分',
     'model/user/visit_err'=>'插入推廣記錄失敗,請重試',
     'model/user/visit_ok'=>'推廣成功',
-    'model/user/reward_tip'=>'用戶【%s、%s】消費%S積分,獲得獎勵%s積分',
+    'model/user/reward_tip'=>'用戶【%s、%s】消費%s積分,獲得獎勵%s積分',
     'model/user/reward_ok'=>'分銷提成成功',
 
     'model/website/refer_max'=> '每日僅能%s次來路記錄',
@@ -1922,8 +1922,8 @@ https://www.baidu.com/123.jpg
     'api/require_comment_name'=>'評論昵稱須err',
     'api/require_comment_name'=>'評論內容必須err',
     'api/never'=>'從未',
-    'api/task_tip_exec'=>'任務:%s,狀態:%s,上次執行時間:%S---執行',
-    'api/task_tip_jump'=>'任務:%s,狀態:%s,上次執行時間:%S---跳過',
+    'api/task_tip_exec'=>'任務:%s,狀態:%s,上次執行時間:%s---執行',
+    'api/task_tip_jump'=>'任務:%s,狀態:%s,上次執行時間:%s---跳過',
 
 
     'install/title'=>'蘋果CMS-V10系統安裝',