TransWikia.com

How to delete a large amount of nodes effeciently during cron?

Drupal Answers Asked by athakhan on February 12, 2021

I implemented hook_cron() to delete nodes older than 30 days using node_delete function. Tracing the performance displays this:

2015-07-06 21:28:49 Drupal watchdog
ApCleanup::node_delete|/fpe/article||0||Node ID 423466 has been
deleted [1.1173 secs]
request_id=”v-b8288e7a-2415-11e5-b14b-22000aeb06a5″

A single node deletion takes 1.1 sec. What is the most efficient way to delete the (2075546) nodes using hook_cron() and the node_delete_multiple function?

One Answer

I would not recommend using Cron for this task.Since you have so many nodes it would always time out. Your better off using Drush and the Delete All module.

Or if you're fully purging all your nodes for instance I have written an SQL script before I can invoke with Drush which uses the sql truncate command to remove all data from Fields of a content type and then does a delete all from node and node_revisions for the given content type, and url aliases -- etc. Using SQL makes such a task take very little time for hundreds of thousands of nodes.

EDIT:

The Delete All admin UI has options for a quick delete that uses sql JOINs and not node_delete. See the admin form code: http://cgit.drupalcode.org/delete_all/tree/delete_all.module#n71

I suggest you install and try using the module.

Answered by tenken on February 12, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP