-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move Archive.php archive invalidation to Loader… #15616
Changes from 15 commits
c8b6c3c
a3fb62a
143c9c3
f218967
2dd4958
70e5513
55e2435
f2890f9
e45ba01
9e24cb2
7c34b24
e9ba420
52498fd
72d886b
0272cc1
ff933b0
a95cfd5
c0c682e
b8e727a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -981,6 +981,16 @@ private function isThereAValidArchiveForPeriod($idSite, $period, $date, $segment | |
$periodsToCheck = [Factory::build($period, $date, Site::getTimezoneFor($idSite))]; | ||
} | ||
|
||
$isTodayIncluded = $this->isTodayIncludedInPeriod($idSite, $periodsToCheck); | ||
$isLast = preg_match('/^last([0-9]+)/', $date, $matches); | ||
|
||
// don't do this check for a single period that includes today | ||
if ($isTodayIncluded | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @diosmosis not 100% understanding this part.
Not sure it's clear what I mean? Or maybe this is not needed anymore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The idea here was if it was a single period like, For Maybe I can add some tests for this code too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added tests, maybe you can better see what it's trying to do There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fully getting it now 👍 |
||
&& !$isLast | ||
) { | ||
return [false, null]; | ||
} | ||
|
||
$periodsToCheckRanges = array_map(function (Period $p) { return $p->getRangeString(); }, $periodsToCheck); | ||
|
||
$this->invalidateArchivedReportsForSitesThatNeedToBeArchivedAgain(); | ||
|
@@ -998,13 +1008,13 @@ private function isThereAValidArchiveForPeriod($idSite, $period, $date, $segment | |
} | ||
|
||
$diff = array_diff($periodsToCheckRanges, $foundArchivePeriods); | ||
$isThereArchiveForAllPeriods = empty($diff); | ||
$isThereArchiveForAllPeriods = empty($diff) && !$isTodayIncluded; | ||
|
||
// if there is an invalidated archive within the range, find out the oldest one and how far it is from today, | ||
// and change the lastN $date to be value so it is correctly re-processed. | ||
$newDate = $date; | ||
if (!$isThereArchiveForAllPeriods | ||
&& preg_match('/^last([0-9]+)/', $date, $matches) | ||
&& $isLast | ||
) { | ||
$lastNValue = (int) $matches[1]; | ||
|
||
|
@@ -1033,6 +1043,26 @@ private function isThereAValidArchiveForPeriod($idSite, $period, $date, $segment | |
return [$isThereArchiveForAllPeriods, $newDate]; | ||
} | ||
|
||
/** | ||
* @param int $idSite | ||
* @param Period[] $periods | ||
* @return bool | ||
* @throws Exception | ||
*/ | ||
private function isTodayIncludedInPeriod($idSite, $periods) | ||
{ | ||
$timezone = Site::getTimezoneFor($idSite); | ||
$today = Date::factoryInTimezone('today', $timezone); | ||
|
||
foreach ($periods as $period) { | ||
if ($period->isDateInPeriod($today)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @param $idSite | ||
* @return array | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@diosmosis might be good to add some tests for this maybe? Like it could return the invalidated date/siteIds which we then can test against?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added tests