Skip to content
GitLab
Explorer
Connexion
S'inscrire
Navigation principale
Rechercher ou aller à…
Projet
S
stats-facil
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneur
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
facil
stats-facil
Validations
9db6f75a
Valider
9db6f75a
rédigé
il y a 10 ans
par
m.kurzeja
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Small changes in purgeInvalidatedArchives query
parent
8ae9e539
Aucune branche associée trouvée
Branches contenant la validation
Aucune étiquette associée trouvée
Étiquettes contenant la validation
Aucune requête de fusion associée trouvée
Modifications
2
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
2 fichiers modifiés
core/DataAccess/ArchivePurger.php
+100
-94
100 ajouts, 94 suppressions
core/DataAccess/ArchivePurger.php
tests/PHPUnit/Integration/ArchiveInvalidationTest.php
+0
-1
0 ajout, 1 suppression
tests/PHPUnit/Integration/ArchiveInvalidationTest.php
avec
100 ajouts
et
95 suppressions
core/DataAccess/ArchivePurger.php
+
100
−
94
Voir le fichier @
9db6f75a
...
@@ -20,108 +20,114 @@ use Piwik\Piwik;
...
@@ -20,108 +20,114 @@ use Piwik\Piwik;
*
*
* @package Piwik\DataAccess
* @package Piwik\DataAccess
*/
*/
class
ArchivePurger
class
ArchivePurger
{
{
public
static
function
purgeInvalidatedArchives
()
{
public
static
function
purgeInvalidatedArchives
()
$archiveTables
=
ArchiveTableCreator
::
getTablesArchivesInstalled
();
{
$archiveTables
=
ArchiveTableCreator
::
getTablesArchivesInstalled
();
foreach
(
$archiveTables
as
$archiveTable
)
{
/**
foreach
(
$archiveTables
as
$archiveTable
)
{
* Select the archives that have already been invalidated and have been since re-processed.
$query
=
'
* It purges records for each distinct { archive name (includes segment hash) , idsite, date, period } tuple.
*/
$query
=
'
SELECT t1.idarchive FROM `'
.
$archiveTable
.
'` t1
SELECT t1.idarchive FROM `'
.
$archiveTable
.
'` t1
INNER JOIN `'
.
$archiveTable
.
'` t2
INNER JOIN `'
.
$archiveTable
.
'` t2
ON t1.name = t2.name AND t1.idsite=t2.idsite
ON t1.name = t2.name AND t1.idsite=t2.idsite
AND t1.date1=t2.date1 AND t1.date2=t2.date2 AND t1.period=t2.period
AND t1.date1=t2.date1 AND t1.date2=t2.date2 AND t1.period=t2.period
WHERE t1.value = 4 AND t2.value IN('
.
ArchiveWriter
::
DONE_OK
.
', '
.
ArchiveWriter
::
DONE_OK_TEMPORARY
.
') AND t1.name LIKE \'done%\''
;
WHERE t1.value = '
.
ArchiveWriter
::
DONE_INVALIDATED
.
'
$result
=
Db
::
fetchAll
(
$query
);
AND t2.value IN('
.
ArchiveWriter
::
DONE_OK
.
', '
.
ArchiveWriter
::
DONE_OK_TEMPORARY
.
')
AND t1.ts_archived < t2.ts_archived AND t1.name LIKE \'done%\''
;
if
(
count
(
$result
)
>
0
)
{
$archiveIds
=
array_map
(
$result
=
Db
::
fetchAll
(
$query
);
function
(
$elm
)
{
return
$elm
[
'idarchive'
];
if
(
count
(
$result
)
>
0
)
{
},
$archiveIds
=
array_map
(
$result
function
(
$elm
)
{
);
return
$elm
[
'idarchive'
];
},
$date
=
ArchiveTableCreator
::
getDateFromTableName
(
$archiveTable
);
$result
$date
=
Date
::
factory
(
str_replace
(
'_'
,
'-'
,
$date
)
.
'-01'
);
);
self
::
deleteArchiveIds
(
$date
,
$archiveIds
);
$date
=
ArchiveTableCreator
::
getDateFromTableName
(
$archiveTable
);
}
$date
=
Date
::
factory
(
str_replace
(
'_'
,
'-'
,
$date
)
.
'-01'
);
}
self
::
deleteArchiveIds
(
$date
,
$archiveIds
);
}
}
}
public
static
function
purgeOutdatedArchives
(
Date
$dateStart
)
}
{
$purgeArchivesOlderThan
=
Rules
::
shouldPurgeOutdatedArchives
(
$dateStart
);
if
(
!
$purgeArchivesOlderThan
)
{
public
static
function
purgeOutdatedArchives
(
Date
$dateStart
)
{
return
;
$purgeArchivesOlderThan
=
Rules
::
shouldPurgeOutdatedArchives
(
$dateStart
);
}
if
(
!
$purgeArchivesOlderThan
)
{
return
;
$idArchivesToDelete
=
self
::
getTemporaryArchiveIdsOlderThan
(
$dateStart
,
$purgeArchivesOlderThan
);
}
if
(
!
empty
(
$idArchivesToDelete
))
{
self
::
deleteArchiveIds
(
$dateStart
,
$idArchivesToDelete
);
$idArchivesToDelete
=
self
::
getTemporaryArchiveIdsOlderThan
(
$dateStart
,
$purgeArchivesOlderThan
);
}
if
(
!
empty
(
$idArchivesToDelete
)
)
{
self
::
deleteArchivesWithPeriodRange
(
$dateStart
);
self
::
deleteArchiveIds
(
$dateStart
,
$idArchivesToDelete
);
}
Log
::
debug
(
"Purging temporary archives: done [ purged archives older than %s in %s ] [Deleted IDs: %s]"
,
self
::
deleteArchivesWithPeriodRange
(
$dateStart
);
$purgeArchivesOlderThan
,
$dateStart
->
toString
(
"Y-m"
),
implode
(
','
,
$idArchivesToDelete
));
}
Log
::
debug
(
"Purging temporary archives: done [ purged archives older than %s in %s ] [Deleted IDs: %s]"
,
$purgeArchivesOlderThan
,
protected
static
function
getTemporaryArchiveIdsOlderThan
(
Date
$date
,
$purgeArchivesOlderThan
)
$dateStart
->
toString
(
"Y-m"
),
{
implode
(
','
,
$idArchivesToDelete
)
);
$query
=
"SELECT idarchive
}
FROM "
.
ArchiveTableCreator
::
getNumericTable
(
$date
)
.
"
protected
static
function
getTemporaryArchiveIdsOlderThan
(
Date
$date
,
$purgeArchivesOlderThan
)
{
$query
=
"SELECT idarchive
FROM "
.
ArchiveTableCreator
::
getNumericTable
(
$date
)
.
"
WHERE name LIKE 'done%'
WHERE name LIKE 'done%'
AND (( value = "
.
ArchiveWriter
::
DONE_OK_TEMPORARY
.
"
AND (( value = "
.
ArchiveWriter
::
DONE_OK_TEMPORARY
.
"
AND ts_archived < ?)
AND ts_archived < ?)
OR value = "
.
ArchiveWriter
::
DONE_ERROR
.
")"
;
OR value = "
.
ArchiveWriter
::
DONE_ERROR
.
")"
;
$result
=
Db
::
fetchAll
(
$query
,
array
(
$purgeArchivesOlderThan
));
$result
=
Db
::
fetchAll
(
$query
,
array
(
$purgeArchivesOlderThan
)
);
$idArchivesToDelete
=
array
();
$idArchivesToDelete
=
array
();
if
(
!
empty
(
$result
))
{
if
(
!
empty
(
$result
)
)
{
foreach
(
$result
as
$row
)
{
foreach
(
$result
as
$row
)
{
$idArchivesToDelete
[]
=
$row
[
'idarchive'
];
$idArchivesToDelete
[]
=
$row
[
'idarchive'
];
}
}
}
}
return
$idArchivesToDelete
;
}
return
$idArchivesToDelete
;
}
/*
* Deleting "Custom Date Range" reports after 1 day, since they can be re-processed and would take up un-necessary space
/*
*/
* Deleting "Custom Date Range" reports after 1 day, since they can be re-processed and would take up un-necessary space
protected
static
function
deleteArchivesWithPeriodRange
(
Date
$date
)
*/
{
protected
static
function
deleteArchivesWithPeriodRange
(
Date
$date
)
{
$query
=
"DELETE FROM %s WHERE period = ? AND ts_archived < ?"
;
$query
=
"DELETE FROM %s WHERE period = ? AND ts_archived < ?"
;
$yesterday
=
Date
::
factory
(
'yesterday'
)
->
getDateTime
();
$yesterday
=
Date
::
factory
(
'yesterday'
)
->
getDateTime
();
$bind
=
array
(
Piwik
::
$idPeriods
[
'range'
],
$yesterday
);
$bind
=
array
(
Piwik
::
$idPeriods
[
'range'
],
$yesterday
);
$numericTable
=
ArchiveTableCreator
::
getNumericTable
(
$date
);
$numericTable
=
ArchiveTableCreator
::
getNumericTable
(
$date
);
Db
::
query
(
sprintf
(
$query
,
$numericTable
),
$bind
);
Db
::
query
(
sprintf
(
$query
,
$numericTable
),
$bind
);
Log
::
debug
(
"Purging Custom Range archives: done [ purged archives older than %s from %s / blob ]"
,
$yesterday
,
$numericTable
);
Log
::
debug
(
"Purging Custom Range archives: done [ purged archives older than %s from %s / blob ]"
,
try
{
$yesterday
,
Db
::
query
(
sprintf
(
$query
,
ArchiveTableCreator
::
getBlobTable
(
$date
)),
$bind
);
$numericTable
);
}
catch
(
Exception
$e
)
{
try
{
// Individual blob tables could be missing
Db
::
query
(
sprintf
(
$query
,
ArchiveTableCreator
::
getBlobTable
(
$date
)
),
$bind
);
}
}
catch
(
Exception
$e
)
{
}
// Individual blob tables could be missing
}
protected
static
function
deleteArchiveIds
(
Date
$date
,
$idArchivesToDelete
)
}
{
$batches
=
array_chunk
(
$idArchivesToDelete
,
1000
);
protected
static
function
deleteArchiveIds
(
Date
$date
,
$idArchivesToDelete
)
{
foreach
(
$batches
as
$idsToDelete
)
{
$batches
=
array_chunk
(
$idArchivesToDelete
,
1000
);
$query
=
"DELETE FROM %s WHERE idarchive IN ("
.
implode
(
','
,
$idsToDelete
)
.
")"
;
foreach
(
$batches
as
$idsToDelete
)
{
$query
=
"DELETE FROM %s WHERE idarchive IN ("
.
implode
(
','
,
$idsToDelete
)
.
")"
;
Db
::
query
(
sprintf
(
$query
,
ArchiveTableCreator
::
getNumericTable
(
$date
)));
try
{
Db
::
query
(
sprintf
(
$query
,
ArchiveTableCreator
::
getNumericTable
(
$date
)
)
);
Db
::
query
(
sprintf
(
$query
,
ArchiveTableCreator
::
getBlobTable
(
$date
)));
try
{
}
catch
(
Exception
$e
)
{
Db
::
query
(
sprintf
(
$query
,
ArchiveTableCreator
::
getBlobTable
(
$date
)
)
);
// Individual blob tables could be missing
}
catch
(
Exception
$e
)
{
}
// Individual blob tables could be missing
}
}
}
}
}
}
}
Ce diff est replié.
Cliquez pour l'agrandir.
tests/PHPUnit/Integration/ArchiveInvalidationTest.php
+
0
−
1
Voir le fichier @
9db6f75a
...
@@ -81,7 +81,6 @@ class ArchiveInvalidationTest extends IntegrationTestCase
...
@@ -81,7 +81,6 @@ class ArchiveInvalidationTest extends IntegrationTestCase
public
function
testAnotherApi
(
$api
,
$params
)
public
function
testAnotherApi
(
$api
,
$params
)
{
{
$this
->
setBrowserArchivingTriggering
(
1
);
$this
->
setBrowserArchivingTriggering
(
1
);
$this
->
invalidateTestArchives
();
$this
->
runApiTests
(
$api
,
$params
);
$this
->
runApiTests
(
$api
,
$params
);
}
}
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter