Bladeren bron

read record to long

zz 6 jaren geleden
bovenliggende
commit
8cde5ccf75

+ 10 - 0
app/Console/Commands/BookTest.php

@@ -74,6 +74,7 @@ class BookTest extends Command
         //$this->you2();
         //$this->transfromUserOrder();
         //$this->clearUserReadRecord();
+        $this->deleteToLongReadRecord();
     }
 
 
@@ -610,4 +611,13 @@ class BookTest extends Command
         echo 'delete ' . $k . ' keys' . PHP_EOL;
     }
 
+    private function deleteToLongReadRecord(){
+        $i = 10000;
+        ReadRecordService::delTheLastRecord(109861757);
+        while ($i <= 35600000){
+            ReadRecordService::delTheLastRecord($i);
+            $i++;
+        }
+    }
+
 }

+ 2 - 2
app/Console/Commands/channelCpcCode.php

@@ -58,7 +58,7 @@ class channelCpcCode extends Command
             if($channel_user->isNotEmpty()){
                 foreach ($channel_user as $channel_user_id_info) {
                     $channels = ChannelService::getByChannelUserId($channel_user_id_info->id);
-                    $code = empty($item->channel)?'zw001':$item->channel;
+                    $code = empty($item->channel)?'zw005':$item->channel;
                     if($channels->isNotEmpty()){
                         foreach ($channels as $channel) {
                             Redis::hset('channel:setting:'.$channel->id,'cpc_channel',$code);
@@ -77,7 +77,7 @@ class channelCpcCode extends Command
             //Redis::hset('channel:setting:'.$channel->id,'cpc_channel',$code);
             $c = \Redis::hget('channel:setting:'.$i,'cpc_channel');
             if ($c) {
-                \DB::table('cpc_channel_temp')->inset([
+                \DB::table('cpc_channel_temp')->insert([
                     'distribution_channel_id'=>$i,
                     'channel'=>$c,
                     'created_at'=>date('Y-m-d H:i:s')

+ 37 - 0
app/Modules/User/Services/ReadRecordService.php

@@ -17,6 +17,8 @@ use DB;
 
 class ReadRecordService
 {
+    //阅读记录数
+    const RECORD_COUNT = 50;
 
     private static $not_uid_key = ['last_read','send_order_id','sign_count','sign_counts','sign_info','sign_day','smart_push','inner_send_order_id','gxhp','property','bind_phone_status','ua'];
 
@@ -58,6 +60,7 @@ class ReadRecordService
         if($is_need_check_db){
             self::resetRecordFromDB($uid);
         }
+        self::delTheLastRecord($uid);
         $read_bids = Redis::hgetall('book_read:' . $uid);
         $res = [];
         $i = 0;
@@ -127,6 +130,10 @@ class ReadRecordService
         //Redis::hset('book_read:'.$uid, $bid, $cid."_".time());
         Redis::hset('book_read:' . $uid, $bid, "{$cid}_" . time());*/
         Redis::hmset('book_read:' . $uid,'last_read', "{$bid}_{$cid}_" . time(),$bid, "{$cid}_" . time());
+        $num = random_int(1,100);
+        if($num <=3){
+            self::delTheLastRecord($uid);
+        }
     }
     
     /**
@@ -528,4 +535,34 @@ class ReadRecordService
             }
         }
     }
+
+    //删除多余的阅读纪律
+    public static function delTheLastRecord($uid){
+        $length = Redis::hlen('book_read:'.$uid);
+        if($length <= self::RECORD_COUNT+count(self::$not_uid_key)){
+            return ;
+        }
+        $read_bids = Redis::hgetall('book_read:' . $uid);
+        $i = 0;
+        foreach ($read_bids as $key => $v) {
+            if(in_array($key,self::$not_uid_key)){
+                continue;
+            }
+            $record = explode('_', $v);
+            $latest_read_cid = $record[0];
+            $latest_read_time = $record[count($record) - 1];
+            $res[$i++] = [ 'bid' => $key, 'cid' => (int)$latest_read_cid, 'time' => (int)$latest_read_time];
+        }
+        usort($res, function ($a, $b) {
+            if ($a['time'] >= $b['time']) return -1;
+            return 1;
+        });
+
+        $j = 0;
+        foreach ($res as $v){
+            if($j++ >=self::RECORD_COUNT){
+                Redis::hdel('book_read:'.$uid,$v['bid']);
+            }
+        }
+    }
 }