Example #1
0
 /**
  * Purge all invalidate archives for whom there are newer, valid archives from the archive
  * table that stores data for `$date`.
  *
  * @param Date $date The date identifying the archive table.
  * @return int The total number of archive rows deleted (from both the blog & numeric tables).
  */
 public function purgeInvalidatedArchivesFrom(Date $date)
 {
     $numericTable = ArchiveTableCreator::getNumericTable($date);
     // we don't want to do an INNER JOIN on every row in a archive table that can potentially have tens to hundreds of thousands of rows,
     // so we first look for sites w/ invalidated archives, and use this as a constraint in getInvalidatedArchiveIdsSafeToDelete() below.
     // the constraint will hit an INDEX and speed up the inner join that happens in getInvalidatedArchiveIdsSafeToDelete().
     $idSites = $this->model->getSitesWithInvalidatedArchive($numericTable);
     if (empty($idSites)) {
         $this->logger->debug("No sites with invalidated archives found in {table}.", array('table' => $numericTable));
         return 0;
     }
     $archiveIds = $this->model->getInvalidatedArchiveIdsSafeToDelete($numericTable, $idSites);
     if (empty($archiveIds)) {
         $this->logger->debug("No invalidated archives found in {table} with newer, valid archives.", array('table' => $numericTable));
         return 0;
     }
     $this->logger->info("Found {countArchiveIds} invalidated archives safe to delete in {table}.", array('table' => $numericTable, 'countArchiveIds' => count($archiveIds)));
     $deletedRowCount = $this->deleteArchiveIds($date, $archiveIds);
     $this->logger->debug("Deleted {count} rows in {table} and its associated blob table.", array('table' => $numericTable, 'count' => $deletedRowCount));
     return $deletedRowCount;
 }