[support] Better a node_save or a db_query for a single field ?

Earnie Boyd earnie at users.sourceforge.net
Wed Apr 7 12:09:51 UTC 2010


Michel Morelli wrote:
> Hi all. I have a content type with a cck integer field and I need to
> increment it when user click on a link (user is redirect to another
> page, or similar).
>
> To do this I have two option:
> 1) node_save
> 2) db_query
>
> This node type has a total of 5 cck fields. Other fields does not change
> when user click on that link.
> My site would be a trafficated site so I could have 10 or 100 clicks on
> that link in a single moment.
>
> I think to this code (for sql query solution):
>
> db_query("LOCK TABLES {content_type_gf_product} WRITE,{watchdog} WRITE");
> db_query("UPDATE {content_type_my_type}  set  field_download_stats_value
> = field_download_stats_value+1 where nid = %d and vid = %d",
> $node->nid,$node->vid);
> db_query("UNLOCK TABLES");
>
> Tnx.
>

Why not use something similar to http://drupal.org/project/gotwo to 
track the link clicks?  You can hook_form_alter and/or hook_nodeapi to 
modify the required field view instead of embedding the field with CCK. 
  Then you don't need to worry about the cached pages.

-- 
Earnie
-- http://progw.com
-- http://www.for-my-kids.com


More information about the support mailing list