Differential D14219 Diff 34352 src/applications/conduit/garbagecollector/ConduitLogGarbageCollector.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/conduit/garbagecollector/ConduitLogGarbageCollector.php
| <?php | <?php | ||||
| final class ConduitLogGarbageCollector | final class ConduitLogGarbageCollector | ||||
| extends PhabricatorGarbageCollector { | extends PhabricatorGarbageCollector { | ||||
| const COLLECTORCONST = 'conduit.logs'; | const COLLECTORCONST = 'conduit.logs'; | ||||
| public function getCollectorName() { | public function getCollectorName() { | ||||
| return pht('Conduit Logs'); | return pht('Conduit Logs'); | ||||
| } | } | ||||
| public function getDefaultRetentionPolicy() { | public function getDefaultRetentionPolicy() { | ||||
| return phutil_units('180 days in seconds'); | return phutil_units('180 days in seconds'); | ||||
| } | } | ||||
| public function collectGarbage() { | protected function collectGarbage() { | ||||
| $key = 'gcdaemon.ttl.conduit-logs'; | |||||
| $ttl = PhabricatorEnv::getEnvConfig($key); | |||||
| if ($ttl <= 0) { | |||||
| return false; | |||||
| } | |||||
| $table = new PhabricatorConduitMethodCallLog(); | $table = new PhabricatorConduitMethodCallLog(); | ||||
| $conn_w = $table->establishConnection('w'); | $conn_w = $table->establishConnection('w'); | ||||
| queryfx( | queryfx( | ||||
| $conn_w, | $conn_w, | ||||
| 'DELETE FROM %T WHERE dateCreated < %d | 'DELETE FROM %T WHERE dateCreated < %d | ||||
| ORDER BY dateCreated ASC LIMIT 100', | ORDER BY dateCreated ASC LIMIT 100', | ||||
| $table->getTableName(), | $table->getTableName(), | ||||
| time() - $ttl); | $this->getGarbageEpoch()); | ||||
| return ($conn_w->getAffectedRows() == 100); | return ($conn_w->getAffectedRows() == 100); | ||||
| } | } | ||||
| } | } | ||||