Skip to content

Commit

Permalink
Use database for performing check for intersecting periods being proc…
Browse files Browse the repository at this point in the history
…essed
  • Loading branch information
sgiehl committed Jul 13, 2024
1 parent ba2a23b commit a777d31
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 88 deletions.
22 changes: 15 additions & 7 deletions core/CronArchive/QueueConsumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,37 +432,45 @@ public function canSkipArchiveBecauseNoPoint(array $invalidatedArchive)

public function shouldSkipArchiveBecauseLowerPeriodOrSegmentIsInProgress(array $archiveToProcess)
{
$inProgressArchives = $this->cliMultiRequestParser->getInProgressArchivingCommands();
$inProgressArchives = $this->model->getInvalidationsInProgress(
(int) $archiveToProcess['idsite'],
$archiveToProcess['name'] ?? null,
$archiveToProcess['report'] ?? null
);

$periods = array_flip(Piwik::$idPeriods);

foreach ($inProgressArchives as $archiveBeingProcessed) {
$this->findSegmentForArchive($archiveBeingProcessed);

if (
empty($archiveBeingProcessed['period'])
|| empty($archiveBeingProcessed['date'])
|| empty($archiveBeingProcessed['date1'])
) {
continue;
}

if (
empty($archiveBeingProcessed['idSite'])
|| $archiveBeingProcessed['idSite'] != $archiveToProcess['idsite']
empty($archiveBeingProcessed['idsite'])
|| $archiveBeingProcessed['idsite'] != $archiveToProcess['idsite']
) {
continue; // different site
}

// we don't care about lower periods being concurrent if they are for different segments (that are not "all visits")
if (
!empty($archiveBeingProcessed['segment'])
!empty($archiveBeingProcessed['name'])
&& !empty($archiveToProcess['segment'])
&& $archiveBeingProcessed['segment'] != $archiveToProcess['segment']
&& urldecode($archiveBeingProcessed['segment']) != $archiveToProcess['segment']
) {
continue;
}

$archiveBeingProcessed['periodObj'] = PeriodFactory::build($archiveBeingProcessed['period'], $archiveBeingProcessed['date']);
$archiveBeingProcessed['periodObj'] = PeriodFactory::build($periods[$archiveBeingProcessed['period']], $archiveBeingProcessed['date1']);

if ($this->isArchiveOfLowerPeriod($archiveToProcess, $archiveBeingProcessed)) {
return "lower or same period in progress in another local climulti process (period = {$archiveBeingProcessed['period']}, date = {$archiveBeingProcessed['date']})";
return "lower or same period in progress in another process (period = {$periods[$archiveBeingProcessed['period']]}, date = {$archiveBeingProcessed['date1']})";
}

if ($this->isArchiveNonSegmentAndInProgressArchiveSegment($archiveToProcess, $archiveBeingProcessed)) {
Expand Down
17 changes: 17 additions & 0 deletions core/DataAccess/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,23 @@ public function isSimilarArchiveInProgress($invalidation)
return !empty($result);
}

public function getInvalidationsInProgress(int $idSite, string $name, string $report = null): array
{
$table = Common::prefixTable('archive_invalidations');

$bind = [$idSite, $name, ArchiveInvalidator::INVALIDATION_STATUS_IN_PROGRESS];

if (empty($report)) {
$reportClause = "(report IS NULL OR report = '')";
} else {
$reportClause = "report = ?";
$bind[] = $report;
}

$sql = "SELECT idsite, period, date1, date2, name FROM `$table` WHERE idsite = ? AND `name` = ? AND `status` = ? AND ts_started IS NOT NULL AND $reportClause LIMIT 1";
return Db::fetchAll($sql, $bind);
}

/**
* Gets the next invalidated archive that should be archived in a table.
*
Expand Down
Loading

0 comments on commit a777d31

Please sign in to comment.