Skip to content

Commit

Permalink
improve check for already processed dependent segments
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiehl committed Jul 8, 2024
1 parent 36f97dc commit 4984ad7
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions core/ArchiveProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class ArchiveProcessor

private $numberOfVisitsConverted = false;

private $processedDependentSegments = [];
private static $processedDependentSegments = [];

public function __construct(Parameters $params, ArchiveWriter $archiveWriter, LogAggregator $logAggregator)
{
Expand Down Expand Up @@ -772,10 +772,9 @@ public function processDependentArchive($plugin, $segment)
return;
}

// The below check is meant to avoid archiving the VisitsSummary more often than needed
// If e.g. one plugin depends on a certain segment it will process VisitsSummary first.
// So another plugin depending on VisitsSummary for the same segment doesn't need to be processed.
if (in_array($newSegment->getOriginalString(), $this->processedDependentSegments) && $plugin === 'VisitsSummary') {
// The below check is meant to avoid archiving the same dependency multiple times.
$processedSegmentKey = $params->getSite()->getId() . $params->getDateStart() . $params->getPeriod()->getLabel() . $newSegment->getOriginalString();
if (in_array($processedSegmentKey . $plugin, self::$processedDependentSegments)) {
return;
}

Expand All @@ -785,7 +784,7 @@ public function processDependentArchive($plugin, $segment)

// Ensure to always invalidate VisitsSummary before any other plugin archive.
// Otherwise those archives might get build with outdated VisitsSummary data
if ($plugin !== 'VisitsSummary' && !in_array($newSegment->getOriginalString(), $this->processedDependentSegments)) {
if ($plugin !== 'VisitsSummary' && !in_array($processedSegmentKey . 'VisitsSummary', self::$processedDependentSegments)) {
$invalidator->markArchivesAsInvalidated(
$idSites,
[$params->getDateStart()],
Expand All @@ -803,6 +802,8 @@ public function processDependentArchive($plugin, $segment)

$archiveLoader = new ArchiveProcessor\Loader($parameters);
$archiveLoader->prepareArchive('VisitsSummary');

self::$processedDependentSegments[] = $processedSegmentKey . 'VisitsSummary';
}

$invalidator->markArchivesAsInvalidated(
Expand All @@ -823,7 +824,7 @@ public function processDependentArchive($plugin, $segment)
$archiveLoader = new ArchiveProcessor\Loader($parameters);
$archiveLoader->prepareArchive($plugin);

$this->processedDependentSegments[] = $newSegment->getOriginalString();
self::$processedDependentSegments[] = $processedSegmentKey . $plugin;
} finally {
self::$isRootArchivingRequest = true;
}
Expand Down

0 comments on commit 4984ad7

Please sign in to comment.