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]

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.


The Delete All admin UI has options for a quick delete that uses sql JOINs and not node_delete. See the admin form code:

I suggest you install and try using the module.

Answered by tenken on February 12, 2021

Add your own answers!

Related Questions

Node is not created, but nid is returned

2  Asked on December 26, 2021 by ziobudda


EntityDrupalWrapper->value() causes infinite recursion on user login?

1  Asked on December 24, 2021 by tigertrussell


Feed import breaks due to ajax error

1  Asked on December 24, 2021 by kenpeter


Multi site Image cache issue

0  Asked on December 24, 2021 by user99683


How to make relationships between users

1  Asked on December 22, 2021


Need CKEditor to encode special characters

1  Asked on December 22, 2021 by bemarlan


Checkboxes in a simple form are not displayed

1  Asked on December 22, 2021 by sebish


How to change scheduler date format in *_node_form

1  Asked on December 21, 2021 by oskar-calvo


hiding taxonomy terms on term page

1  Asked on December 21, 2021 by user3027413


TypeError on “drush config-export”

1  Asked on December 21, 2021


“Broken pipe” between Nginx and PHP-FPM

1  Asked on December 21, 2021 by stephen-winnall


Restrict delete operation on a node referenced by another node

2  Asked on December 19, 2021 by user48552


How to perform views date calculations using global math?

2  Asked on December 19, 2021 by tinohuda


Get menu link siblings

4  Asked on December 19, 2021 by erin-mclaughlin


Ask a Question

Get help from others!

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