Delete aggregates that have not been accessed in the last 6 weeks.
Return value
int Count of the number of rows removed from the databases.
2 calls to advagg_remove_old_unused_aggregates()
- advagg_admin_remove_old_unused_aggregates_button in ./
advagg.admin.inc - Delete aggregates that have not been accessed in the last 6 weeks.
- advagg_cron in ./
advagg.module - Implements hook_cron().
File
-
./
advagg.cache.inc, line 627
Code
function advagg_remove_old_unused_aggregates() {
$advagg_aggregates_versions_del = 0;
$advagg_aggregates_del = 0;
// Find orphaned aggregate versions entries.
// Create main query.
$query = db_select('advagg_aggregates_versions', 'aav')->fields('aav', array(
'aggregate_filenames_hash',
))
->groupBy('aav.aggregate_filenames_hash');
// Create join and add in query comment.
$query->leftjoin('advagg_aggregates', 'aa', 'aa.aggregate_filenames_hash=aav.aggregate_filenames_hash');
$query->isNull('aa.aggregate_filenames_hash');
$query->comment('Query called from ' . __FUNCTION__ . '()');
$results = $query->execute();
// If we have an orphaned db entry, delete it.
if (!empty($results)) {
foreach ($results as $row) {
$advagg_aggregates_versions_del += db_delete('advagg_aggregates_versions')->condition('aggregate_filenames_hash', $row->aggregate_filenames_hash)
->execute();
}
}
// Delete aggregate versions that have not been accessed in the last 45 days.
$advagg_aggregates_versions_del += db_delete('advagg_aggregates_versions')->condition('atime', REQUEST_TIME - variable_get('advagg_remove_old_unused_aggregates_time', ADVAGG_REMOVE_OLD_UNUSED_AGGREGATES_TIME), '<')
->execute();
// See if any aggregates are orphaned now.
// Create main query.
$query = db_select('advagg_aggregates', 'aa')->fields('aa', array(
'aggregate_filenames_hash',
))
->groupBy('aa.aggregate_filenames_hash');
// Create join and add in query comment.
$query->leftjoin('advagg_aggregates_versions', 'aav', 'aa.aggregate_filenames_hash=aav.aggregate_filenames_hash');
$query->isNull('aav.aggregate_filenames_hash');
$query->comment('Query called from ' . __FUNCTION__ . '()');
$results = $query->execute();
// If we have an orphaned db entry, delete it.
if (!empty($results)) {
foreach ($results as $row) {
$advagg_aggregates_del += db_delete('advagg_aggregates')->condition('aggregate_filenames_hash', $row->aggregate_filenames_hash)
->execute();
}
}
// Return the total count of entires removed from the database.
return $advagg_aggregates_versions_del + $advagg_aggregates_del;
}