Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'core/Archive/ArchiveInvalidator.php')
-rw-r--r--core/Archive/ArchiveInvalidator.php41
1 files changed, 29 insertions, 12 deletions
diff --git a/core/Archive/ArchiveInvalidator.php b/core/Archive/ArchiveInvalidator.php
index 0ef586fe8c..585c22dd8a 100644
--- a/core/Archive/ArchiveInvalidator.php
+++ b/core/Archive/ArchiveInvalidator.php
@@ -96,7 +96,7 @@ class ArchiveInvalidator
// we do not really have to get the value first. we could simply always try to call set() and it would update or
// insert the record if needed but we do not want to lock the table (especially since there are still some
// MyISAM installations)
- $values = Option::getLike('%' . $this->rememberArchivedReportIdStart . '%');
+ $values = Option::getLike('%' . str_replace('_', '\_', $this->rememberArchivedReportIdStart) . '%');
$all = [];
foreach ($values as $name => $value) {
@@ -121,7 +121,7 @@ class ArchiveInvalidator
// we do not really have to get the value first. we could simply always try to call set() and it would update or
// insert the record if needed but we do not want to lock the table (especially since there are still some
// MyISAM installations)
- $value = Option::getLike('%' . $key . '%');
+ $value = Option::getLike('%' . str_replace('_', '\_', $key) . '%');
}
// getLike() returns an empty array rather than 'false'
@@ -154,7 +154,7 @@ class ArchiveInvalidator
public function getRememberedArchivedReportsThatShouldBeInvalidated()
{
- $reports = Option::getLike('%' . $this->rememberArchivedReportIdStart . '%_%');
+ $reports = Option::getLike('%' . str_replace('_', '\_', $this->rememberArchivedReportIdStart) . '%\_%');
$sitesPerDay = array();
@@ -204,9 +204,11 @@ class ArchiveInvalidator
public function forgetRememberedArchivedReportsToInvalidateForSite($idSite)
{
- $id = $this->buildRememberArchivedReportIdForSite($idSite) . '\_';
- $this->deleteOptionLike($id);
- Cache::clearCacheGeneral();
+ $id = $this->buildRememberArchivedReportIdForSite($idSite) . '_';
+ $hasDeletedSomething = $this->deleteOptionLike($id);
+ if ($hasDeletedSomething) {
+ Cache::clearCacheGeneral();
+ }
}
/**
@@ -220,17 +222,22 @@ class ArchiveInvalidator
// The process pid is added to the end of the entry in order to support multiple concurrent transactions.
// So this must be a deleteLike call to get all the entries, where there used to only be one.
- $this->deleteOptionLike($id);
+ return $this->deleteOptionLike($id);
}
+ /**
+ * @param $id
+ * @return bool true if a record was deleted, false otherwise.
+ * @throws \Zend_Db_Statement_Exception
+ */
private function deleteOptionLike($id)
{
// we're not using deleteLike since it maybe could cause deadlocks see https://github.com/matomo-org/matomo/issues/15545
// we want to reduce number of rows scanned and only delete specific primary key
- $keys = Option::getLike('%' . $id . '%');
+ $keys = Option::getLike('%' . str_replace('_', '\_', $id) . '%');
if (empty($keys)) {
- return;
+ return false;
}
$keys = array_keys($keys);
@@ -238,7 +245,8 @@ class ArchiveInvalidator
$placeholders = Common::getSqlStringFieldsArray($keys);
$table = Common::prefixTable('option');
- Db::query('DELETE FROM `' . $table . '` WHERE `option_name` IN (' . $placeholders . ')', $keys);
+ $db = Db::query('DELETE FROM `' . $table . '` WHERE `option_name` IN (' . $placeholders . ')', $keys);
+ return (bool) $db->rowCount();
}
/**
@@ -250,6 +258,7 @@ class ArchiveInvalidator
* @param bool $forceInvalidateNonexistantRanges set true to force inserting rows for ranges in archive_invalidations
* @param string $name null to make sure every plugin is archived when this invalidation is processed by core:archive,
* or a plugin name to only archive the specific plugin.
+ * @param bool $ignorePurgeLogDataDate
* @return InvalidationResult
* @throws \Exception
*/
@@ -280,6 +289,7 @@ class ArchiveInvalidator
&& count($dates) == 1
&& ((string)$dates[0]) == ((string)Date::factoryInTimezone('today', $tz))
) {
+ // date is for today
$hasMoreThanJustToday[$idSite] = false;
}
}
@@ -315,20 +325,27 @@ class ArchiveInvalidator
$isInvalidatingDays = $period == 'day' || $cascadeDown || empty($period);
$isNotInvalidatingSegment = empty($segment) || empty($segment->getString());
+
if ($isInvalidatingDays
&& $isNotInvalidatingSegment
) {
+
+ $hasDeletedAny = false;
+
foreach ($idSites as $idSite) {
foreach ($dates as $date) {
if (is_string($date)) {
$date = Date::factory($date);
}
- $this->forgetRememberedArchivedReportsToInvalidate($idSite, $date);
+ $hasDeletedAny = $this->forgetRememberedArchivedReportsToInvalidate($idSite, $date) || $hasDeletedAny;
}
}
+
+ if ($hasDeletedAny) {
+ Cache::clearCacheGeneral();
+ }
}
- Cache::clearCacheGeneral();
return $invalidationInfo;
}