Skip to content
Extraits de code Groupes Projets
Valider b22ff349 rédigé par mattab's avatar mattab
Parcourir les fichiers

Creating getMinTimeProcessedForTemporaryArchive and splitting...

Creating getMinTimeProcessedForTemporaryArchive and splitting getMinTimeArchivedProcessed to make it clear.
Renaming class to Piwik_DataAccess_ArchiveSelector -- it will specialize in selecting archives
parent a82321a7
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -41,7 +41,6 @@
*/
class Piwik_Archive
{
const FLAG_ALL_WEBSITES_REQUESTED = 'all';
/**
* When saving DataTables in the DB, we sometimes replace the columns name by these IDs so we save up lots of bytes
* Eg. INDEX_NB_UNIQ_VISITORS is an integer: 4 bytes, but 'nb_uniq_visitors' is 16 bytes at least
......@@ -103,6 +102,8 @@ class Piwik_Archive
const INDEX_GOAL_ECOMMERCE_REVENUE_DISCOUNT = 7;
const INDEX_GOAL_ECOMMERCE_ITEMS = 8;
const REQUEST_ALL_WEBSITES_FLAG = 'all';
public static function getVisitsMetricNames()
{
$names = array();
......@@ -308,7 +309,7 @@ class Piwik_Archive
$allPeriods = array($oPeriod);
}
$segment = new Piwik_Segment($segment, $websiteIds);
$idSiteIsAll = $idSites == self::FLAG_ALL_WEBSITES_REQUESTED;
$idSiteIsAll = $idSites == self::REQUEST_ALL_WEBSITES_FLAG;
return Piwik_Archive::factory($segment, $allPeriods, $websiteIds, $idSiteIsAll);
}
......@@ -516,7 +517,7 @@ class Piwik_Archive
return $result;
}
$archiveData = Piwik_DataAccess_Archiver::getArchiveData($archiveIds, $archiveNames, $archiveDataType, $idSubtable);
$archiveData = Piwik_DataAccess_ArchiveSelector::getArchiveData($archiveIds, $archiveNames, $archiveDataType, $idSubtable);
foreach ($archiveData as $row) {
// values are grouped by idsite (site ID), date1-date2 (date range), then name (field name)
$idSite = $row['idsite'];
......@@ -669,7 +670,7 @@ class Piwik_Archive
*/
private function cacheArchiveIdsWithoutLaunching($plugins)
{
$idarchivesByReport = Piwik_DataAccess_Archiver::getArchiveIds(
$idarchivesByReport = Piwik_DataAccess_ArchiveSelector::getArchiveIds(
$this->params->getIdSites(), $this->params->getPeriods(), $this->params->getSegment(), $plugins);
// initialize archive ID cache for each report
......
Ce diff est replié.
......@@ -8,6 +8,7 @@ class Piwik_ArchiveProcessor_Rules
const OPTION_TODAY_ARCHIVE_TTL = 'todayArchiveTimeToLive';
const OPTION_BROWSER_TRIGGER_ARCHIVING = 'enableBrowserTriggerArchiving';
static public function isBrowserTriggerEnabled()
{
$browserArchivingEnabled = Piwik_GetOption(self::OPTION_BROWSER_TRIGGER_ARCHIVING);
......@@ -16,6 +17,7 @@ class Piwik_ArchiveProcessor_Rules
}
return (bool)Piwik_Config::getInstance()->General['enable_browser_archiving_triggering'];
}
public static function getTodayArchiveTimeToLive()
{
$timeToLive = Piwik_GetOption(self::OPTION_TODAY_ARCHIVE_TTL);
......@@ -93,7 +95,6 @@ class Piwik_ArchiveProcessor_Rules
return $isArchivingDisabled;
}
/**
* Returns the name of the archive field used to tell the status of an archive, (ie,
* whether the archive was created successfully or not).
......@@ -176,15 +177,13 @@ class Piwik_ArchiveProcessor_Rules
else {
$purgeArchivesOlderThan = Piwik_Date::factory('today')->getDateTime();
}
Piwik_DataAccess_Archiver::purgeOutdatedArchives($numericTable, $blobTable, $purgeArchivesOlderThan);
Piwik_DataAccess_ArchiveSelector::purgeOutdatedArchives($numericTable, $blobTable, $purgeArchivesOlderThan);
// these tables will be OPTIMIZEd daily in a scheduled task, to claim lost space
} else {
Piwik::log("Purging temporary archives: skipped.");
}
}
public static function setTodayArchiveTimeToLive($timeToLiveSeconds)
{
$timeToLiveSeconds = (int)$timeToLiveSeconds;
......@@ -193,4 +192,27 @@ class Piwik_ArchiveProcessor_Rules
}
Piwik_SetOption(self::OPTION_TODAY_ARCHIVE_TTL, $timeToLiveSeconds, $autoload = true);
}
static public function getMinTimeProcessedForTemporaryArchive(Piwik_Date $dateStart, Piwik_Period $period, Piwik_Segment $segment,
Piwik_Site $site)
{
$now = time();
$minimumArchiveTime = $now - Piwik_ArchiveProcessor_Rules::getTodayArchiveTimeToLive();
$isArchivingDisabled = Piwik_ArchiveProcessor_Rules::isArchivingDisabledFor($segment, $period->getLabel());
if ($isArchivingDisabled) {
if ($period->getNumberOfSubperiods() == 0
&& $dateStart->getTimestamp() <= $now
) {
$minimumArchiveTime = false;
} else {
// However, if archiving is disabled for this request, we shall
// accept any archive that was processed today after 00:00:01 this morning
$timezone = $site->getTimezone();
$minimumArchiveTime = Piwik_Date::factory(Piwik_Date::factory('now', $timezone)->getDateStartUTC())->setTimezone($timezone)->getTimestamp();
}
}
return $minimumArchiveTime;
}
}
\ No newline at end of file
......@@ -11,8 +11,19 @@
/**
* Data Access object used to query archives, create new archives, and insert data for them.
*
* A record in the Database for a given report is defined by
* - idarchive = unique ID that is associated to all the data of this archive (idsite+period+date)
* - idsite = the ID of the website
* - date1 = starting day of the period
* - date2 = ending day of the period
* - period = integer that defines the period (day/week/etc.). @see period::getId()
* - ts_archived = timestamp when the archive was processed (UTC)
* - name = the name of the report (ex: uniq_visitors or search_keywords_by_search_engines)
* - value = the actual data (a numeric value, or a blob of compressed serialized data)
*
*/
class Piwik_DataAccess_Archiver
class Piwik_DataAccess_ArchiveSelector
{
const NB_VISITS_RECORD_LOOKED_UP = "nb_visits";
const NB_VISITS_CONVERTED_RECORD_LOOKED_UP = "nb_visits_converted";
......@@ -58,8 +69,12 @@ class Piwik_DataAccess_Archiver
*/
static public function getArchiveProcessorLock($idsite, $period, $segment)
{
$lockName = self::getArchiveProcessorLockName($idsite, $period, $segment);
return Piwik_GetDbLock($lockName, $maxRetries = 30);
$result = Piwik_GetDbLock($lockName, $maxRetries = 30);
if(!$result) {
Piwik::log('SELECT GET_LOCK(?, 1) FAILED to acquire lock. Proceeding anyway...');
}
}
/**
......@@ -169,7 +184,9 @@ class Piwik_DataAccess_Archiver
protected static function getVisitsMetricsFromResults($idArchive, $idArchiveVisitsSummary, $results)
{
$visits = $visitsConverted = false;
if($idArchiveVisitsSummary !== false) {
$archiveWithVisitsMetricsWasFound = ($idArchiveVisitsSummary !== false);
if($archiveWithVisitsMetricsWasFound) {
$visits = $visitsConverted = 0;
}
foreach ($results as $result) {
......
......@@ -168,6 +168,7 @@
<name>Visitor ID</name>
<segment>visitorId</segment>
<acceptedValues>34c31e04394bdc63 - any 16 Hexadecimal chars ID, which can be fetched using the Tracking API function getVisitorId()</acceptedValues>
<permission>1</permission>
</row>
<row>
<type>dimension</type>
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter