Skip to content

Commit

Permalink
fixes #5354 Delete archives by batch of 1000 using array_chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
mattab committed Jun 18, 2014
1 parent e4fa667 commit 4361b23
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions core/DataAccess/ArchiveSelector.php
Expand Up @@ -332,14 +332,18 @@ protected static function deleteArchivesWithPeriodRange(Date $date)

protected static function deleteArchiveIds(Date $date, $idArchivesToDelete)
{
$query = "DELETE FROM %s WHERE idarchive IN (" . implode(',', $idArchivesToDelete) . ")";

Db::query(sprintf($query, ArchiveTableCreator::getNumericTable($date)));
try {
Db::query(sprintf($query, ArchiveTableCreator::getBlobTable($date)));
} catch (Exception $e) {
// Individual blob tables could be missing
$batches = array_chunk($idArchivesToDelete, 1000);
foreach($batches as $idsToDelete) {
$query = "DELETE FROM %s WHERE idarchive IN (" . implode(',', $idsToDelete) . ")";

Db::query(sprintf($query, ArchiveTableCreator::getNumericTable($date)));
try {
Db::query(sprintf($query, ArchiveTableCreator::getBlobTable($date)));
} catch (Exception $e) {
// Individual blob tables could be missing
}
}

}

protected static function getTemporaryArchiveIdsOlderThan(Date $date, $purgeArchivesOlderThan)
Expand Down

0 comments on commit 4361b23

Please sign in to comment.