for updating a record count you should not use saveField() but updateAll()See tons of questions and answers on SO like
Am Montag, 24. März 2014 16:23:16 UTC+1 schrieb advantage+:I was under the impression counterCache holds record counts thru the relationships.
I use that when a user has x number of related model records.
In this case it’s a page view count that simply updates when viewed, no relation to anything else there is no User hasMany PageView relationship.
User hasMany Post, Post is viewed, update the view count of that Post.
User counterCache for number of Post for that user but the Post does not 150 PageView records.
Am I missing something?
From: cake...@googlegroups.com [mailto:cake...@googlegroups.com] On Behalf Of John Sposato
To: cake...@googlegroups.com
Sent: Monday, March 24, 2014 12:42 PM
Subject: Re: $this->field and contain
Any reason you can't use counterCache?
On Monday, March 24, 2014 11:07:46 AM UTC-4, advantage+ wrote:Can you use / is there a way to read a field and not add in extra relation queries?
I have a very simple function to read 1 field and update it by +1
public function pageCount($id) {
$this->id = $id;
$count = $this->field('view_count', array('id' => $id)) + 1;
$this->saveField('view_count', $count);
}
Right now the full page has 30 querys exectuted.
Removing this call from the controller.
$this->User->pageCount($user['User']['id']);
And the page queries drop to 23. Odd how a simple call to read 1 field and update by 1 creates 7 queries.
Looking at the extra queries its pulling in related models.
I can write a find and use contain => false I suppose but figured I would ask.
--To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+u...@googlegroups.com.
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment