0

I need to count every day about 10,000 records of one of the fields of the node. Now I use the following scheme:
1. getting list of nodes db_select
2. I load and save all nodes with new values (node_load and node_save) in foreach.

This process has become a heavy load on the server and I want to use to change the db_update fields.

function mymodule_select_nids() {
  db_select...
  retutn $nids
}

$nids[0][nid] = 250; $nids[0][rating] = 108; $nids[0][daycount] = 375
$nids[1][nid] = 251; $nids[1][rating] = 525; $nids[1][daycount] = 138

function mymodule_update_fields($nids) {
  foreach ($nids as $node) {
  $fiels_new_rating = (rating + daycoun)/2
  db_update record ...
  }
}

My question is: can one query to the database (db_update) the records of the entire table or do I need to update each record in the table in foreach?

UPD
If you update 10,000 records, what works faster than db_update against node_load and node_save?

  • No - the query would be e.g. UPDATE ... WHERE id = 1 for node 1, UPDATE ... WHERE id = 2, and so on, with a different count for each row. You need separate queries for that. Unless you bundle all nids with common values into a single query, that'd work. But it's probably not practical – Clive May 17 '18 at 10:20
  • @Clive, спасибо. – Hubix7 May 17 '18 at 10:30
  • I don’t speak that language... – Clive May 17 '18 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.