1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 14:00:56 +01:00

Add a very forgiving GC for Differential viewstate information

Summary:
Ref T13455. Viewstates are fairly small and will probably grow less quickly than the changeset table, but the data is also not important to retain in the long term: if you revisit a change several months after hiding some files, it's fine if we've forgotten that you adjusted the view parameters.

Add a GC with a long default collection policy (180 days) so installs can manage the size of this table if it becomes necessary.

Test Plan: Ran via `bin/garbage` to adjust the GC policy and collect viewstates.

Maniphest Tasks: T13455

Differential Revision: https://secure.phabricator.com/D21164
This commit is contained in:
epriestley 2020-04-23 13:54:34 -07:00
parent e20feeeee9
commit d05d8f6558
3 changed files with 34 additions and 0 deletions

View file

@ -715,6 +715,7 @@ phutil_register_library_map(array(
'DifferentialUnitTestResult' => 'applications/differential/constants/DifferentialUnitTestResult.php',
'DifferentialUpdateRevisionConduitAPIMethod' => 'applications/differential/conduit/DifferentialUpdateRevisionConduitAPIMethod.php',
'DifferentialViewState' => 'applications/differential/storage/DifferentialViewState.php',
'DifferentialViewStateGarbageCollector' => 'applications/differential/garbagecollector/DifferentialViewStateGarbageCollector.php',
'DifferentialViewStateQuery' => 'applications/differential/query/DifferentialViewStateQuery.php',
'DiffusionAuditorDatasource' => 'applications/diffusion/typeahead/DiffusionAuditorDatasource.php',
'DiffusionAuditorFunctionDatasource' => 'applications/diffusion/typeahead/DiffusionAuditorFunctionDatasource.php',
@ -6803,6 +6804,7 @@ phutil_register_library_map(array(
'DifferentialDAO',
'PhabricatorPolicyInterface',
),
'DifferentialViewStateGarbageCollector' => 'PhabricatorGarbageCollector',
'DifferentialViewStateQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'DiffusionAuditorDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'DiffusionAuditorFunctionDatasource' => 'PhabricatorTypeaheadCompositeDatasource',

View file

@ -0,0 +1,29 @@
<?php
final class DifferentialViewStateGarbageCollector
extends PhabricatorGarbageCollector {
const COLLECTORCONST = 'differential.viewstate';
public function getCollectorName() {
return pht('Differential View States');
}
public function getDefaultRetentionPolicy() {
return phutil_units('180 days in seconds');
}
protected function collectGarbage() {
$table = new DifferentialViewState();
$conn = $table->establishConnection('w');
queryfx(
$conn,
'DELETE FROM %R WHERE dateModified < %d LIMIT 100',
$table,
$this->getGarbageEpoch());
return ($conn->getAffectedRows() == 100);
}
}

View file

@ -23,6 +23,9 @@ final class DifferentialViewState
'key_object' => array(
'columns' => array('objectPHID'),
),
'key_modified' => array(
'columns' => array('dateModified'),
),
),
) + parent::getConfiguration();
}