PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 8, 2022

[FIXED] The "save" method of model class works very long

 March 08, 2022     mysql, php, yii, yii2, yii2-model     No comments   

Issue

I have such method in controller, that simple sets value of status field to 0 or 1.

public function actionNews_status($id,$status){
    $status = ($status==1)?1:0;
    $number = false;
    $news = News::findOne($id);
    if(!is_null($news)){
        $news->status = $status;
        $number = $news->save();
        Redis::rset($CACHE_mat, null);
    }
    return json_encode(['status'=>$number]);
}

As it turned out, the method works for about 20 seconds.

I found out that line $number = $news->save(); is working slowly. I checked this with exit before and after this line. I also found out that the status field itself is updated immediately, since the query to the table instantly shows the changes. But the save method continues after that to work for a long time.

status field defined as TINYINT(1) NULL DEFAULT 0 and no have any indexes.

Maybe creation of index is to helps fix it?

MySQL database, InnoDB. In the table 78701 rows.

Updated:

I found out the following. Slowly running the afterSave method call at the end of the updateInternal. But before the line with this call, the script is executed quickly. Slowly works a call the afterSave by itself, not a code inside afterSave method and not code before afterSave calling Why this can happen?


Solution

Problem solved. Cause was found in overrided afterSave method in model class.



Answered By - evgeny_s
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing