Sunday, July 4, 2010

Re: Unnecessary Queries??

What debug level are you using? See /app/core.php = Configure::write('debug', 2);

Jeremy Burns
Class Outfit

jeremyburns@classoutfit.com
http://www.classoutfit.com

On 5 Jul 2010, at 02:36, clearflysystems@googlemail.com wrote:

> Hi Bakers,
>
> I have a simple reordering script setup ->
> Very Basic Data Array -
> [Product] => Array(
> [0] => Array(
> ['id'] => 6,
> ['sort_order'] => 1
> ),
> [1] => Array(
> ['id'] => 7,
> ['sort_order'] => 2
> ),
> etc......
> )
>
> Then Saving the data:
> foreach($this->data['Product'] as $product){
> $this->Product->save($product);
> }
>
> When saving this data cake is executing 3 Count queries for each
> 'Product' and i can't figure out why the hell it even needs to execute
> one of them let alone the same query 3 times.
>
> 2 SELECT COUNT(*) AS `count` FROM `products` AS `Product` WHERE
> `Product`.`id` = 6
> 3 SELECT COUNT(*) AS `count` FROM `products` AS `Product` WHERE
> `Product`.`id` = 6
> 4 SELECT COUNT(*) AS `count` FROM `products` AS `Product` WHERE
> `Product`.`id` = 6
> 5 UPDATE `products` SET `id` = 6, `sort_order` = 1 WHERE
> `products`.`id` = 6
>
> So reordering say 10 items produces 40 Queries.
>
> Using saveAll instead of save actually produces another Count Query
> for each row (so saveAll on 10 items ends up with 50 Queries) hence
> the foreach method.
>
> Product Recursive = -1.
>
> Product relationships:
> public $belongsTo = array(
> 'Category' => array(
> 'className' => 'Category',
> 'foreignKey' => 'category_id'
> )
> );
> public $hasMany = array(
> 'Image' => array(
> 'className' => 'Image',
> 'foreignKey' => 'product_id',
> 'dependent' => true,
> 'exclusive' => true
> ),
> 'ProductBid' => array(
> 'className' => 'ProductBid',
> 'foreignKey' => 'product_id',
> 'dependent' => true,
> 'exclusive' => true
> )
> );
>
> Any ideas as to why all the Unnecessary Queries or what i might be
> doing wrong?
> Thanks
> Simon
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
>
> You received this message because you are subscribed to the Google Groups "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

No comments: