zoukankan      html  css  js  c++  java
  • PHP处理大数据量老用户头像更新的操作--解决数据量大超时的问题

        /**
         * @title 老用户头像更新--每3秒调用一次接口,每次更新10条数据
         * @example user/createHeadPicForOldUser?
         * @method GET
         * @author 邹柯
         */
        public function createHeadPicForOldUserAction(){
            $domain=$_SERVER['HTTP_HOST'];
            $ob = new UserModel();
            $user=M('user');
            $u_where="head_pic is null or head_pic=''";
            $count=$user->where($u_where)->count();
            $user_info=$user->field('user_id')->where($u_where)->page(1,10)->select();
            if($count !=0){
                for($i=0;$i<10;$i++){
                    //获取一个默认头像
                    $h_pic=$ob->getDefaultUserHeadPic();
                    $re=$user->data(['head_pic'=>$h_pic])->where(['user_id'=>$user_info[$i]['user_id']])->save();
                }
                echo "还剩".$count."条记录没更新";
                exit("<script>setTimeout(function(){location.href='http://$domain/user/createHeadPicForOldUser';},3000);</script>");
            }else{
                exit("更新完毕");
            }        
            
        }
        //注册时给用户分配一个随机头像(或老用户登录时给其分配一个随机头像)
        public function getDefaultUserHeadPic(){
            $default_avatar=M('default_avatar a');
            $avatar_style=M('avatar_style s');
            $da_where['a.is_deleted']=0;
            $da_where['a.status']=1;
            $da_where['s.is_deleted']=0;
            $da_where['s.status']=1;
            $default_avatar_info=$default_avatar->field("a.id,img as head_pic")
                    ->join('left join lc_avatar_style s on a.style_id=s.id')
                    ->where($da_where)
                    ->select();  
            $cn=count($default_avatar_info);
            $cs=rand(0,$cn-1);
            return $default_avatar_info[$cs]['head_pic'];
        }    
  • 相关阅读:
    正睿提高组2017模拟题三T1
    数位dp【转载】
    正睿提高组2017模拟题二T2
    【树状数组二维区间加+区间查询模板】bzoj3132
    【树状数组区间加+区间查询模板】洛谷P3372
    51Nod
    CodeForces 631E Product Sum
    CodeForces
    [不知道哪来的题] 完美理论
    CodeForces
  • 原文地址:https://www.cnblogs.com/zouke1220/p/9096507.html
Copyright © 2011-2022 走看看