Updating the last_used column in the path_redirect table is resulting in some overhead. On our site, we never discard redirects. Can we add another variable to toggle whether that last_used column is updated?

Here's the diff:

diff --git a/path_redirect.admin.inc b/path_redirect.admin.inc
index 2cd4146..6b05808 100644
--- a/path_redirect.admin.inc
+++ b/path_redirect.admin.inc
@@ -523,10 +523,26 @@ function path_redirect_settings_form() {
     '#default_value' => variable_get('path_redirect_default_status', 301),
     '#options' => path_redirect_status_code_options(),
   );
+  $form['path_redirect_disable_update_last_used'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Disable updating last_used column during a redirect.'),
+    '#description' => t('Administrators only! This will disable updating the last_used timestamp when a user is redirected.'),
+    '#default_value' => variable_get('path_redirect_disable_update_last_used', 0),
+  );
 
   return system_settings_form($form);
 }
 
+/**
+ * Do not disable updating of last_used column unless redirects are never deleted.
+ */
+function path_redirect_settings_form_validate($form, &$form_state) {
+  if ($form_state['values']['path_redirect_disable_update_last_used'] == 1
+    && $form_state['values']['path_redirect_purge_inactive'] != '0') {
+    form_set_error('path_redirect_disable_update_last_used', t('Cannot disable updating of last_used timestamp unless redirects are never purged.'));
+  }
+}
+
 function path_redirect_status_code_options() {
   return array(
     300 => t('300 Multiple Choices'),
diff --git a/path_redirect.module b/path_redirect.module
index ebfd435..a5ee1a5 100644
--- a/path_redirect.module
+++ b/path_redirect.module
@@ -118,7 +118,9 @@ function path_redirect_goto($redirect = NULL) {
     $redirect['redirect_url'] = url($redirect['redirect'], array('query' => $redirect['query'], 'fragment' => $redirect['fragment'], 'absolute' => TRUE));
 
     // Update the last used timestamp so that unused redirects can be purged.
-    db_query("UPDATE {path_redirect} SET last_used = %d WHERE rid = %d", time(), $redirect['rid']);
+    if (!variable_get('path_redirect_disable_update_last_used', 0)) {
+      db_query("UPDATE {path_redirect} SET last_used = %d WHERE rid = %d", time(), $redirect['rid']);
+    }
 
     if (url($redirect['redirect']) == url($_GET['q'])) {
       // Prevent infinite loop redirection.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

djbobbydrake’s picture

Status: Active » Needs review
FileSize
2.14 KB

Patch attached.