This project is not covered by Drupal’s security advisory policy.

Postpone hook implementations to queue processing.

The idea is that while it is great to be able to perform a lot of actions when something happens (entity is saved, updated, deleted etc.) many are not exactly time critical.

For example, when saving an existing taxonomy term, it is not crucial that all pathauto generated URLs that use a taxonomy term in that hierarchy are updated instantly.
Or when a node is saved, updating the search index is naturally important, but it is not necessarily something that needs to be done before the editor's next page reload.

By postponing actions from hooks, we can give a better user experience where subsequent page loads are not waiting for non-critical code to be executed.

Usage

Similar to any standard hook implementation, just adding "_queued" to the function name.

Example:

<?php
function mymodule_taxonomy_term_insert_queued($term) {
  error_log("Hey, I'm a cron queue! $term->tid has been inserted, let's act on it!");
}
?>

Optionally support queued hook invokation:

<?php
function _mymodule_taxonomy_term_insert($term) {
  error_log("Hey! $term->tid has been inserted, let's act on it! I may be queued by setting the variable 'mymodule_use_queue'");
}

function mymodule_taxonomy_term_insert($term) {
  if (module_exists('queued_invoke') && variable_get('mymodule_use_queue')) {
    queued_invoke_queue_hook('mymodule', 'taxonomy_term_insert_queued', func_get_args(), '_mymodule_taxonomy_term_insert');
  }
  else {
    _mymodule_taxonomy_term_insert($term)
  }
}
?>

Supported hooks

comment_presave
comment_insert()
comment_update()
comment_delete()
field_presave()
field_insert()
field_update()
field_delete()
field_attach_presave()
field_attach_insert()
field_attach_update()
field_attach_delete()
field_storage_delete()
field_storage_pre_insert()
field_storage_pre_update()
filter_format_insert()
filter_format_update()
image_style_save()
image_style_delete()
menu_insert()
menu_update()
menu_delete()
node_delete()
node_revision_delete()
node_insert()
node_presave()
node_update()
node_type_insert()
node_type_update()
node_type_delete()
delete()
insert()
update()
path_insert()
path_update()
path_delete()
entity_presave()
entity_insert()
entity_update()
entity_delete()
menu_link_insert()
menu_link_update()
menu_link_delete()
file_presave()
file_insert()
file_update()
file_delete()
actions_delete()
taxonomy_vocabulary_presave()
taxonomy_vocabulary_insert()
taxonomy_vocabulary_update()
taxonomy_vocabulary_delete()
taxonomy_term_presave()
taxonomy_term_insert()
taxonomy_term_update()
taxonomy_term_delete()
user_delete()
user_presave()
user_insert()
user_update()
user_login()
user_logout()
user_role_presave()
user_role_insert()
user_role_update()
user_role_delete()

Project information

Releases