tidjean Posted March 12, 2013 Share Posted March 12, 2013 (edited) Hello, I write my own module to integrate products and categories from my CSV's supplier. function create_category($name, $parent_id = false){ $time_start = microtime_float(); $time_end = microtime_float(); $time = $time_end - $time_start; echo "\n -a-".$time." secondes\n"; $object = new Category(); $time_end = microtime_float(); $time = $time_end - $time_start; echo "\n -b-".$time." secondes\n"; $object->name = $name; $time_end = microtime_float(); $time = $time_end - $time_start; echo "\n -c-".$time." secondes\n"; if (!$parent_id){ $parent_id = Configuration::get('PS_HOME_CATEGORY'); } $time_end = microtime_float(); $time = $time_end - $time_start; echo "\n -d-".$time." secondes\n"; $object->id_parent = $parent_id; $object->link_rewrite = array((int)(Configuration::get('PS_LANG_DEFAULT')) => fix_string($name,'url')); $time_end = microtime_float(); $time = $time_end - $time_start; echo "\n -e-".$time." secondes\n"; $object->add(); $time_end = microtime_float(); $time = $time_end - $time_start; echo "\n -f-".$time." secondes\n"; $object->id_category = $object->id; $object->id_category_default = $object->id; $time_end = microtime_float(); $time = $time_end - $time_start; echo "\n -g-".$time." secondes\n"; $object->update(); $time_end = microtime_float(); $time = $time_end - $time_start; echo "\n -h-".$time." secondes\n"; return $object; } here the result for the first product : -a-1.3113021850586E-5 secondes -b-0.00010800361633301 secondes -c-0.00011801719665527 secondes -d-0.00013613700866699 secondes -e-0.00015497207641602 secondes -f-0.52572512626648 secondes -g-0.52575492858887 secondes -h-1.1281881332397 secondes Here the result of the 150th product : 150 -a-1.1920928955078E-5 secondes -b-0.00010490417480469 secondes -c-0.00011491775512695 secondes -d-0.0001220703125 secondes -e-0.00014686584472656 secondes -f-5.7645740509033 secondes -g-5.7646059989929 secondes -h-11.38772892952 secondes And the 290tn product : 290 -a-1.5020370483398E-5 secondes -b-0.00013995170593262 secondes -c-0.0001530647277832 secondes -d-0.00017595291137695 secondes -e-0.0001990795135498 secondes -f-8.4670760631561 secondes -g-8.46710896492 secondes -h-20.849717140198 secondes As you can see, the step "f" and "h" take more and more time to execute. It's the function : Category::add() Category::update() But I dont understand why, any suggestion? Edited April 6, 2013 by tidjean (see edit history) Link to comment Share on other sites More sharing options...
tidjean Posted March 19, 2013 Author Share Posted March 19, 2013 (edited) [sOLVED] Hello, I found the problem, it's because the system rebuild my tree category. So I add this line before save my category : $object->doNotRegenerateNTree =1; So my function is : (No more timestamp) function create_category($name, $parent_id = false){ if($name && $name != ''){ $object = new Category(); $object->name = $name; if (!$parent_id){ $parent_id = Configuration::get('PS_HOME_CATEGORY'); } $object->id_parent = $parent_id; $object->link_rewrite = array((int)(Configuration::get('PS_LANG_DEFAULT')) => fix_string($name,'url')); $object->doNotRegenerateNTree =1; //add product $object->add(); $object->id_category = $object->id; $object->id_category_default = $object->id; $object->update(); return $object; } } Edited March 19, 2013 by tidjean (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now