diff -u b/modules/redirect_404/redirect_404.module b/modules/redirect_404/redirect_404.module --- b/modules/redirect_404/redirect_404.module +++ b/modules/redirect_404/redirect_404.module @@ -45,7 +45,7 @@ // For row limit n, get the wid of the nth row in descending wid order. // Counting the most recent n rows avoids issues with wid number sequences, // e.g. auto_increment value > 1 or rows deleted directly from the table. - if ($row_limit > 0) { + /*if ($row_limit > 0) { $query = \Drupal::database()->select('redirect_404', 'r404') ->extend('Drupal\Core\Database\Query\TableSortExtender') ->orderBy('timestamp', 'DESC') @@ -60,7 +60,7 @@ ->condition('timestamp', $query, '<') ->execute(); } - } + }*/ } /** diff -u b/modules/redirect_404/src/RedirectNotFoundStorage.php b/modules/redirect_404/src/RedirectNotFoundStorage.php --- b/modules/redirect_404/src/RedirectNotFoundStorage.php +++ b/modules/redirect_404/src/RedirectNotFoundStorage.php @@ -74,24 +74,18 @@ // Cleanup the redirect_404 table. $row_limit = \Drupal::config('redirect_404.settings')->get('row_limit'); - // For row limit n, get the wid of the nth row in descending wid order. - // Counting the most recent n rows avoids issues with wid number sequences, - // e.g. auto_increment value > 1 or rows deleted directly from the table. - $query = $this->database->select('redirect_404', 'r404'); - //$query->fields('r404'); - $query->addExpression('pow(2, -(UNIX_TIMESTAMP(NOW()) - timestamp)/86400)', 'boh'); - //$query->condition('relevancy', 0.99, '>'); - $query->orderBy('boh', 'DESC'); - - $query->fields('r404'); - $query->condition('relevancy', 0.99, '>'); - $result = $query->execute()->fetchAll(); - - if ($result) { - $delete = $this->database->select('redirect_404', 'r404'); - $delete->condition('path', $result, 'NOT IN'); - $result = $delete->execute()->fetchAll(); - } + + // Determine cutoff level. + $select = $this->database->query('SELECT path, langcode, (relevancy * pow(2, -(UNIX_TIMESTAMP(NOW()) - timestamp)/' . $this->halflife . ')) as cutoff FROM {redirect_404} ORDER BY (relevancy * pow(2, -(UNIX_TIMESTAMP(NOW()) - timestamp)/' . $this->halflife . ')) DESC LIMIT ' . $row_limit . ', 1')->fetchObject(); + + // Delete records below cutoff. + $delete = $this->database->query('DELETE FROM {redirect_404} WHERE (relevancy * pow(2, -(UNIX_TIMESTAMP(NOW()) - timestamp)/' . $this->halflife . ')) < :cutoff', [':cutoff' => $select->cutoff]); + + + //$result = $result->cutoff; + $result['select'] = $select->cutoff; + $result['delete'] = $delete; + return $result; }