@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Complete modularization of the GC daemon

Summary: This modularizes the rest of the GC submethods. Turned out there was nothing tricky.

Test Plan: Ran `bin/phd debug garbage` and got reasonable looking behavior and output.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D7971

+259 -234
+18
src/__phutil_library_map__.php
··· 259 259 'ConduitAPI_user_whoami_Method' => 'applications/people/conduit/ConduitAPI_user_whoami_Method.php', 260 260 'ConduitCall' => 'applications/conduit/call/ConduitCall.php', 261 261 'ConduitCallTestCase' => 'applications/conduit/call/__tests__/ConduitCallTestCase.php', 262 + 'ConduitConnectionGarbageCollector' => 'applications/conduit/garbagecollector/ConduitConnectionGarbageCollector.php', 262 263 'ConduitException' => 'applications/conduit/protocol/ConduitException.php', 264 + 'ConduitLogGarbageCollector' => 'applications/conduit/garbagecollector/ConduitLogGarbageCollector.php', 263 265 'ConduitSSHWorkflow' => 'applications/conduit/ssh/ConduitSSHWorkflow.php', 264 266 'ConpherenceActionMenuEventListener' => 'applications/conpherence/events/ConpherenceActionMenuEventListener.php', 265 267 'ConpherenceConfigOptions' => 'applications/conpherence/config/ConpherenceConfigOptions.php', ··· 413 415 'DifferentialNewDiffMail' => 'applications/differential/mail/DifferentialNewDiffMail.php', 414 416 'DifferentialPHIDTypeDiff' => 'applications/differential/phid/DifferentialPHIDTypeDiff.php', 415 417 'DifferentialPHIDTypeRevision' => 'applications/differential/phid/DifferentialPHIDTypeRevision.php', 418 + 'DifferentialParseCacheGarbageCollector' => 'applications/differential/garbagecollector/DifferentialParseCacheGarbageCollector.php', 416 419 'DifferentialParseRenderTestCase' => 'applications/differential/__tests__/DifferentialParseRenderTestCase.php', 417 420 'DifferentialPathFieldSpecification' => 'applications/differential/field/specification/DifferentialPathFieldSpecification.php', 418 421 'DifferentialPrimaryPaneView' => 'applications/differential/view/DifferentialPrimaryPaneView.php', ··· 1236 1239 'PhabricatorBuiltinPatchList' => 'infrastructure/storage/patch/PhabricatorBuiltinPatchList.php', 1237 1240 'PhabricatorBusyExample' => 'applications/uiexample/examples/PhabricatorBusyExample.php', 1238 1241 'PhabricatorCacheDAO' => 'applications/cache/storage/PhabricatorCacheDAO.php', 1242 + 'PhabricatorCacheGeneralGarbageCollector' => 'applications/cache/garbagecollector/PhabricatorCacheGeneralGarbageCollector.php', 1239 1243 'PhabricatorCacheManagementPurgeWorkflow' => 'applications/cache/management/PhabricatorCacheManagementPurgeWorkflow.php', 1240 1244 'PhabricatorCacheManagementWorkflow' => 'applications/cache/management/PhabricatorCacheManagementWorkflow.php', 1245 + 'PhabricatorCacheMarkupGarbageCollector' => 'applications/cache/garbagecollector/PhabricatorCacheMarkupGarbageCollector.php', 1246 + 'PhabricatorCacheTTLGarbageCollector' => 'applications/cache/garbagecollector/PhabricatorCacheTTLGarbageCollector.php', 1241 1247 'PhabricatorCaches' => 'applications/cache/PhabricatorCaches.php', 1242 1248 'PhabricatorCalendarBrowseController' => 'applications/calendar/controller/PhabricatorCalendarBrowseController.php', 1243 1249 'PhabricatorCalendarController' => 'applications/calendar/controller/PhabricatorCalendarController.php', ··· 1350 1356 'PhabricatorDaemonLogEvent' => 'applications/daemon/storage/PhabricatorDaemonLogEvent.php', 1351 1357 'PhabricatorDaemonLogEventViewController' => 'applications/daemon/controller/PhabricatorDaemonLogEventViewController.php', 1352 1358 'PhabricatorDaemonLogEventsView' => 'applications/daemon/view/PhabricatorDaemonLogEventsView.php', 1359 + 'PhabricatorDaemonLogGarbageCollector' => 'applications/daemon/garbagecollector/PhabricatorDaemonLogGarbageCollector.php', 1353 1360 'PhabricatorDaemonLogListController' => 'applications/daemon/controller/PhabricatorDaemonLogListController.php', 1354 1361 'PhabricatorDaemonLogListView' => 'applications/daemon/view/PhabricatorDaemonLogListView.php', 1355 1362 'PhabricatorDaemonLogQuery' => 'applications/daemon/query/PhabricatorDaemonLogQuery.php', ··· 1364 1371 'PhabricatorDaemonManagementStopWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementStopWorkflow.php', 1365 1372 'PhabricatorDaemonManagementWorkflow' => 'applications/daemon/management/PhabricatorDaemonManagementWorkflow.php', 1366 1373 'PhabricatorDaemonReference' => 'infrastructure/daemon/control/PhabricatorDaemonReference.php', 1374 + 'PhabricatorDaemonTaskGarbageCollector' => 'applications/daemon/garbagecollector/PhabricatorDaemonTaskGarbageCollector.php', 1367 1375 'PhabricatorDataNotAttachedException' => 'infrastructure/storage/lisk/PhabricatorDataNotAttachedException.php', 1368 1376 'PhabricatorDebugController' => 'applications/system/PhabricatorDebugController.php', 1369 1377 'PhabricatorDefaultFileStorageEngineSelector' => 'applications/files/engineselector/PhabricatorDefaultFileStorageEngineSelector.php', ··· 1472 1480 'PhabricatorFileStorageConfigurationException' => 'applications/files/exception/PhabricatorFileStorageConfigurationException.php', 1473 1481 'PhabricatorFileStorageEngine' => 'applications/files/engine/PhabricatorFileStorageEngine.php', 1474 1482 'PhabricatorFileStorageEngineSelector' => 'applications/files/engineselector/PhabricatorFileStorageEngineSelector.php', 1483 + 'PhabricatorFileTemporaryGarbageCollector' => 'applications/files/garbagecollector/PhabricatorFileTemporaryGarbageCollector.php', 1475 1484 'PhabricatorFileTestCase' => 'applications/files/storage/__tests__/PhabricatorFileTestCase.php', 1476 1485 'PhabricatorFileTestDataGenerator' => 'applications/files/lipsum/PhabricatorFileTestDataGenerator.php', 1477 1486 'PhabricatorFileTransaction' => 'applications/files/storage/PhabricatorFileTransaction.php', ··· 2699 2708 'ConduitAPI_user_removestatus_Method' => 'ConduitAPI_user_Method', 2700 2709 'ConduitAPI_user_whoami_Method' => 'ConduitAPI_user_Method', 2701 2710 'ConduitCallTestCase' => 'PhabricatorTestCase', 2711 + 'ConduitConnectionGarbageCollector' => 'PhabricatorGarbageCollector', 2702 2712 'ConduitException' => 'Exception', 2713 + 'ConduitLogGarbageCollector' => 'PhabricatorGarbageCollector', 2703 2714 'ConduitSSHWorkflow' => 'PhabricatorSSHWorkflow', 2704 2715 'ConpherenceActionMenuEventListener' => 'PhabricatorEventListener', 2705 2716 'ConpherenceConfigOptions' => 'PhabricatorApplicationConfigOptions', ··· 2847 2858 'DifferentialNewDiffMail' => 'DifferentialReviewRequestMail', 2848 2859 'DifferentialPHIDTypeDiff' => 'PhabricatorPHIDType', 2849 2860 'DifferentialPHIDTypeRevision' => 'PhabricatorPHIDType', 2861 + 'DifferentialParseCacheGarbageCollector' => 'PhabricatorGarbageCollector', 2850 2862 'DifferentialParseRenderTestCase' => 'PhabricatorTestCase', 2851 2863 'DifferentialPathFieldSpecification' => 'DifferentialFieldSpecification', 2852 2864 'DifferentialPrimaryPaneView' => 'AphrontView', ··· 3803 3815 'PhabricatorBuiltinPatchList' => 'PhabricatorSQLPatchList', 3804 3816 'PhabricatorBusyExample' => 'PhabricatorUIExample', 3805 3817 'PhabricatorCacheDAO' => 'PhabricatorLiskDAO', 3818 + 'PhabricatorCacheGeneralGarbageCollector' => 'PhabricatorGarbageCollector', 3806 3819 'PhabricatorCacheManagementPurgeWorkflow' => 'PhabricatorCacheManagementWorkflow', 3807 3820 'PhabricatorCacheManagementWorkflow' => 'PhabricatorManagementWorkflow', 3821 + 'PhabricatorCacheMarkupGarbageCollector' => 'PhabricatorGarbageCollector', 3822 + 'PhabricatorCacheTTLGarbageCollector' => 'PhabricatorGarbageCollector', 3808 3823 'PhabricatorCalendarBrowseController' => 'PhabricatorCalendarController', 3809 3824 'PhabricatorCalendarController' => 'PhabricatorController', 3810 3825 'PhabricatorCalendarDAO' => 'PhabricatorLiskDAO', ··· 3944 3959 'PhabricatorDaemonLogEvent' => 'PhabricatorDaemonDAO', 3945 3960 'PhabricatorDaemonLogEventViewController' => 'PhabricatorDaemonController', 3946 3961 'PhabricatorDaemonLogEventsView' => 'AphrontView', 3962 + 'PhabricatorDaemonLogGarbageCollector' => 'PhabricatorGarbageCollector', 3947 3963 'PhabricatorDaemonLogListController' => 'PhabricatorDaemonController', 3948 3964 'PhabricatorDaemonLogListView' => 'AphrontView', 3949 3965 'PhabricatorDaemonLogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', ··· 3957 3973 'PhabricatorDaemonManagementStatusWorkflow' => 'PhabricatorDaemonManagementWorkflow', 3958 3974 'PhabricatorDaemonManagementStopWorkflow' => 'PhabricatorDaemonManagementWorkflow', 3959 3975 'PhabricatorDaemonManagementWorkflow' => 'PhabricatorManagementWorkflow', 3976 + 'PhabricatorDaemonTaskGarbageCollector' => 'PhabricatorGarbageCollector', 3960 3977 'PhabricatorDataNotAttachedException' => 'Exception', 3961 3978 'PhabricatorDebugController' => 'PhabricatorController', 3962 3979 'PhabricatorDefaultFileStorageEngineSelector' => 'PhabricatorFileStorageEngineSelector', ··· 4079 4096 'PhabricatorFileShortcutController' => 'PhabricatorFileController', 4080 4097 'PhabricatorFileStorageBlob' => 'PhabricatorFileDAO', 4081 4098 'PhabricatorFileStorageConfigurationException' => 'Exception', 4099 + 'PhabricatorFileTemporaryGarbageCollector' => 'PhabricatorGarbageCollector', 4082 4100 'PhabricatorFileTestCase' => 'PhabricatorTestCase', 4083 4101 'PhabricatorFileTestDataGenerator' => 'PhabricatorTestDataGenerator', 4084 4102 'PhabricatorFileTransaction' => 'PhabricatorApplicationTransaction',
+26
src/applications/cache/garbagecollector/PhabricatorCacheGeneralGarbageCollector.php
··· 1 + <?php 2 + 3 + final class PhabricatorCacheGeneralGarbageCollector 4 + extends PhabricatorGarbageCollector { 5 + 6 + public function collectGarbage() { 7 + $key = 'gcdaemon.ttl.general-cache'; 8 + $ttl = PhabricatorEnv::getEnvConfig($key); 9 + if ($ttl <= 0) { 10 + return false; 11 + } 12 + 13 + $cache = new PhabricatorKeyValueDatabaseCache(); 14 + $conn_w = $cache->establishConnection('w'); 15 + 16 + queryfx( 17 + $conn_w, 18 + 'DELETE FROM %T WHERE cacheCreated < %d 19 + ORDER BY cacheCreated ASC LIMIT 100', 20 + $cache->getTableName(), 21 + time() - $ttl); 22 + 23 + return ($conn_w->getAffectedRows() == 100); 24 + } 25 + 26 + }
+25
src/applications/cache/garbagecollector/PhabricatorCacheMarkupGarbageCollector.php
··· 1 + <?php 2 + 3 + final class PhabricatorCacheMarkupGarbageCollector 4 + extends PhabricatorGarbageCollector { 5 + 6 + public function collectGarbage() { 7 + $key = 'gcdaemon.ttl.markup-cache'; 8 + $ttl = PhabricatorEnv::getEnvConfig($key); 9 + if ($ttl <= 0) { 10 + return false; 11 + } 12 + 13 + $table = new PhabricatorMarkupCache(); 14 + $conn_w = $table->establishConnection('w'); 15 + 16 + queryfx( 17 + $conn_w, 18 + 'DELETE FROM %T WHERE dateCreated < %d LIMIT 100', 19 + $table->getTableName(), 20 + time() - $ttl); 21 + 22 + return ($conn_w->getAffectedRows() == 100); 23 + } 24 + 25 + }
+20
src/applications/cache/garbagecollector/PhabricatorCacheTTLGarbageCollector.php
··· 1 + <?php 2 + 3 + final class PhabricatorCacheTTLGarbageCollector 4 + extends PhabricatorGarbageCollector { 5 + 6 + public function collectGarbage() { 7 + $cache = new PhabricatorKeyValueDatabaseCache(); 8 + $conn_w = $cache->establishConnection('w'); 9 + 10 + queryfx( 11 + $conn_w, 12 + 'DELETE FROM %T WHERE cacheExpires < %d 13 + ORDER BY cacheExpires ASC LIMIT 100', 14 + $cache->getTableName(), 15 + time()); 16 + 17 + return ($conn_w->getAffectedRows() == 100); 18 + } 19 + 20 + }
+25
src/applications/conduit/garbagecollector/ConduitConnectionGarbageCollector.php
··· 1 + <?php 2 + 3 + final class ConduitConnectionGarbageCollector 4 + extends PhabricatorGarbageCollector { 5 + 6 + public function collectGarbage() { 7 + $key = 'gcdaemon.ttl.conduit-logs'; 8 + $ttl = PhabricatorEnv::getEnvConfig($key); 9 + if ($ttl <= 0) { 10 + return false; 11 + } 12 + 13 + $table = new PhabricatorConduitConnectionLog(); 14 + $conn_w = $table->establishConnection('w'); 15 + queryfx( 16 + $conn_w, 17 + 'DELETE FROM %T WHERE dateCreated < %d 18 + ORDER BY dateCreated ASC LIMIT 100', 19 + $table->getTableName(), 20 + time() - $ttl); 21 + 22 + return ($conn_w->getAffectedRows() == 100); 23 + } 24 + 25 + }
+25
src/applications/conduit/garbagecollector/ConduitLogGarbageCollector.php
··· 1 + <?php 2 + 3 + final class ConduitLogGarbageCollector 4 + extends PhabricatorGarbageCollector { 5 + 6 + public function collectGarbage() { 7 + $key = 'gcdaemon.ttl.conduit-logs'; 8 + $ttl = PhabricatorEnv::getEnvConfig($key); 9 + if ($ttl <= 0) { 10 + return false; 11 + } 12 + 13 + $table = new PhabricatorConduitMethodCallLog(); 14 + $conn_w = $table->establishConnection('w'); 15 + queryfx( 16 + $conn_w, 17 + 'DELETE FROM %T WHERE dateCreated < %d 18 + ORDER BY dateCreated ASC LIMIT 100', 19 + $table->getTableName(), 20 + time() - $ttl); 21 + 22 + return ($conn_w->getAffectedRows() == 100); 23 + } 24 + 25 + }
+24
src/applications/daemon/garbagecollector/PhabricatorDaemonLogGarbageCollector.php
··· 1 + <?php 2 + 3 + final class PhabricatorDaemonLogGarbageCollector 4 + extends PhabricatorGarbageCollector { 5 + 6 + public function collectGarbage() { 7 + $ttl = PhabricatorEnv::getEnvConfig('gcdaemon.ttl.daemon-logs'); 8 + if ($ttl <= 0) { 9 + return false; 10 + } 11 + 12 + $table = new PhabricatorDaemonLogEvent(); 13 + $conn_w = $table->establishConnection('w'); 14 + 15 + queryfx( 16 + $conn_w, 17 + 'DELETE FROM %T WHERE epoch < %d LIMIT 100', 18 + $table->getTableName(), 19 + time() - $ttl); 20 + 21 + return ($conn_w->getAffectedRows() == 100); 22 + } 23 + 24 + }
+48
src/applications/daemon/garbagecollector/PhabricatorDaemonTaskGarbageCollector.php
··· 1 + <?php 2 + 3 + final class PhabricatorDaemonTaskGarbageCollector 4 + extends PhabricatorGarbageCollector { 5 + 6 + public function collectGarbage() { 7 + $key = 'gcdaemon.ttl.task-archive'; 8 + $ttl = PhabricatorEnv::getEnvConfig($key); 9 + if ($ttl <= 0) { 10 + return false; 11 + } 12 + 13 + $table = new PhabricatorWorkerArchiveTask(); 14 + $data_table = new PhabricatorWorkerTaskData(); 15 + $conn_w = $table->establishConnection('w'); 16 + 17 + $rows = queryfx_all( 18 + $conn_w, 19 + 'SELECT id, dataID FROM %T WHERE dateCreated < %d LIMIT 100', 20 + $table->getTableName(), 21 + time() - $ttl); 22 + 23 + if (!$rows) { 24 + return false; 25 + } 26 + 27 + $data_ids = array_filter(ipull($rows, 'dataID')); 28 + $task_ids = ipull($rows, 'id'); 29 + 30 + $table->openTransaction(); 31 + if ($data_ids) { 32 + queryfx( 33 + $conn_w, 34 + 'DELETE FROM %T WHERE id IN (%Ld)', 35 + $data_table->getTableName(), 36 + $data_ids); 37 + } 38 + queryfx( 39 + $conn_w, 40 + 'DELETE FROM %T WHERE id IN (%Ld)', 41 + $table->getTableName(), 42 + $task_ids); 43 + $table->saveTransaction(); 44 + 45 + return (count($task_ids) == 100); 46 + } 47 + 48 + }
+25
src/applications/differential/garbagecollector/DifferentialParseCacheGarbageCollector.php
··· 1 + <?php 2 + 3 + final class DifferentialParseCacheGarbageCollector 4 + extends PhabricatorGarbageCollector { 5 + 6 + public function collectGarbage() { 7 + $key = 'gcdaemon.ttl.differential-parse-cache'; 8 + $ttl = PhabricatorEnv::getEnvConfig($key); 9 + if ($ttl <= 0) { 10 + return false; 11 + } 12 + 13 + $table = new DifferentialChangeset(); 14 + $conn_w = $table->establishConnection('w'); 15 + 16 + queryfx( 17 + $conn_w, 18 + 'DELETE FROM %T WHERE dateCreated < %d LIMIT 100', 19 + DifferentialChangeset::TABLE_CACHE, 20 + time() - $ttl); 21 + 22 + return ($conn_w->getAffectedRows() == 100); 23 + } 24 + 25 + }
+18
src/applications/files/garbagecollector/PhabricatorFileTemporaryGarbageCollector.php
··· 1 + <?php 2 + 3 + final class PhabricatorFileTemporaryGarbageCollector 4 + extends PhabricatorGarbageCollector { 5 + 6 + public function collectGarbage() { 7 + $files = id(new PhabricatorFile())->loadAllWhere( 8 + 'ttl < %d LIMIT 100', 9 + time()); 10 + 11 + foreach ($files as $file) { 12 + $file->delete(); 13 + } 14 + 15 + return (count($files) == 100); 16 + } 17 + 18 + }
+5 -234
src/infrastructure/daemon/garbagecollector/PhabricatorGarbageCollectorDaemon.php
··· 3 3 /** 4 4 * Collects old logs and caches to reduce the amount of data stored in the 5 5 * database. 6 - * 7 - * @group daemon 8 6 */ 9 7 final class PhabricatorGarbageCollectorDaemon extends PhabricatorDaemon { 10 8 ··· 14 12 ->loadObjects(); 15 13 16 14 do { 17 - $n_daemon = $this->collectDaemonLogs(); 18 - $n_parse = $this->collectParseCaches(); 19 - $n_markup = $this->collectMarkupCaches(); 20 - $n_tasks = $this->collectArchivedTasks(); 21 - $n_cache_ttl = $this->collectGeneralCacheTTL(); 22 - $n_cache = $this->collectGeneralCaches(); 23 - $n_files = $this->collectExpiredFiles(); 24 - $n_clogs = $this->collectExpiredConduitLogs(); 25 - $n_ccons = $this->collectExpiredConduitConnections(); 26 - 27 - $collected = array( 28 - 'Daemon Log' => $n_daemon, 29 - 'Differential Parse Cache' => $n_parse, 30 - 'Markup Cache' => $n_markup, 31 - 'Archived Tasks' => $n_tasks, 32 - 'General Cache TTL' => $n_cache_ttl, 33 - 'General Cache Entries' => $n_cache, 34 - 'Temporary Files' => $n_files, 35 - 'Conduit Logs' => $n_clogs, 36 - 'Conduit Connections' => $n_ccons, 37 - ); 38 - $collected = array_filter($collected); 39 - 40 - foreach ($collected as $thing => $count) { 41 - $count = number_format($count); 42 - $this->log("Garbage collected {$count} '{$thing}' objects."); 43 - } 44 - 45 - $total = array_sum($collected); 46 - 47 - // TODO: This logic is unnecessarily complex for now to facilitate a 48 - // gradual conversion to the new GC infrastructure. 49 - 50 - $had_more_garbage = false; 51 15 foreach ($collectors as $name => $collector) { 52 16 $more_garbage = false; 53 17 do { ··· 58 22 } 59 23 60 24 $more_garbage = $collector->collectGarbage(); 61 - if ($more_garbage) { 62 - $had_more_garbage = true; 63 - } 64 25 $this->stillWorking(); 65 26 } while ($more_garbage); 66 27 } 67 28 68 - if ($had_more_garbage) { 69 - $total += 100; 70 - } 71 - 72 - if ($total < 100) { 73 - // We didn't max out any of the GCs so we're basically caught up. Ease 74 - // off the GC loop so we don't keep doing table scans just to delete 75 - // a handful of rows; wake up in a few hours. 76 - $this->sleep(4 * (60 * 60)); 77 - } else { 78 - $this->stillWorking(); 79 - } 29 + // We made it to the end of the run cycle of every GC, so we're more or 30 + // less caught up. Ease off the GC loop so we don't keep doing table 31 + // scans just to delete a handful of rows; wake up in a few hours. 32 + $this->log(pht('All caught up, waiting for more garbage.')); 33 + $this->sleep(4 * (60 * 60)); 80 34 } while (true); 81 35 82 - } 83 - 84 - private function collectDaemonLogs() { 85 - $ttl = PhabricatorEnv::getEnvConfig('gcdaemon.ttl.daemon-logs'); 86 - if ($ttl <= 0) { 87 - return 0; 88 - } 89 - 90 - $table = new PhabricatorDaemonLogEvent(); 91 - $conn_w = $table->establishConnection('w'); 92 - 93 - queryfx( 94 - $conn_w, 95 - 'DELETE FROM %T WHERE epoch < %d LIMIT 100', 96 - $table->getTableName(), 97 - time() - $ttl); 98 - 99 - return $conn_w->getAffectedRows(); 100 - } 101 - 102 - private function collectParseCaches() { 103 - $key = 'gcdaemon.ttl.differential-parse-cache'; 104 - $ttl = PhabricatorEnv::getEnvConfig($key); 105 - if ($ttl <= 0) { 106 - return 0; 107 - } 108 - 109 - $table = new DifferentialChangeset(); 110 - $conn_w = $table->establishConnection('w'); 111 - 112 - queryfx( 113 - $conn_w, 114 - 'DELETE FROM %T WHERE dateCreated < %d LIMIT 100', 115 - DifferentialChangeset::TABLE_CACHE, 116 - time() - $ttl); 117 - 118 - return $conn_w->getAffectedRows(); 119 - } 120 - 121 - private function collectMarkupCaches() { 122 - $key = 'gcdaemon.ttl.markup-cache'; 123 - $ttl = PhabricatorEnv::getEnvConfig($key); 124 - if ($ttl <= 0) { 125 - return 0; 126 - } 127 - 128 - $table = new PhabricatorMarkupCache(); 129 - $conn_w = $table->establishConnection('w'); 130 - 131 - queryfx( 132 - $conn_w, 133 - 'DELETE FROM %T WHERE dateCreated < %d LIMIT 100', 134 - $table->getTableName(), 135 - time() - $ttl); 136 - 137 - return $conn_w->getAffectedRows(); 138 - } 139 - 140 - private function collectArchivedTasks() { 141 - $key = 'gcdaemon.ttl.task-archive'; 142 - $ttl = PhabricatorEnv::getEnvConfig($key); 143 - if ($ttl <= 0) { 144 - return 0; 145 - } 146 - 147 - $table = new PhabricatorWorkerArchiveTask(); 148 - $data_table = new PhabricatorWorkerTaskData(); 149 - $conn_w = $table->establishConnection('w'); 150 - 151 - $rows = queryfx_all( 152 - $conn_w, 153 - 'SELECT id, dataID FROM %T WHERE dateCreated < %d LIMIT 100', 154 - $table->getTableName(), 155 - time() - $ttl); 156 - 157 - if (!$rows) { 158 - return 0; 159 - } 160 - 161 - $data_ids = array_filter(ipull($rows, 'dataID')); 162 - $task_ids = ipull($rows, 'id'); 163 - 164 - $table->openTransaction(); 165 - if ($data_ids) { 166 - queryfx( 167 - $conn_w, 168 - 'DELETE FROM %T WHERE id IN (%Ld)', 169 - $data_table->getTableName(), 170 - $data_ids); 171 - } 172 - queryfx( 173 - $conn_w, 174 - 'DELETE FROM %T WHERE id IN (%Ld)', 175 - $table->getTableName(), 176 - $task_ids); 177 - $table->saveTransaction(); 178 - 179 - return count($task_ids); 180 - } 181 - 182 - 183 - private function collectGeneralCacheTTL() { 184 - $cache = new PhabricatorKeyValueDatabaseCache(); 185 - $conn_w = $cache->establishConnection('w'); 186 - 187 - queryfx( 188 - $conn_w, 189 - 'DELETE FROM %T WHERE cacheExpires < %d 190 - ORDER BY cacheExpires ASC LIMIT 100', 191 - $cache->getTableName(), 192 - time()); 193 - 194 - return $conn_w->getAffectedRows(); 195 - } 196 - 197 - 198 - private function collectGeneralCaches() { 199 - $key = 'gcdaemon.ttl.general-cache'; 200 - $ttl = PhabricatorEnv::getEnvConfig($key); 201 - if ($ttl <= 0) { 202 - return 0; 203 - } 204 - 205 - $cache = new PhabricatorKeyValueDatabaseCache(); 206 - $conn_w = $cache->establishConnection('w'); 207 - 208 - queryfx( 209 - $conn_w, 210 - 'DELETE FROM %T WHERE cacheCreated < %d 211 - ORDER BY cacheCreated ASC LIMIT 100', 212 - $cache->getTableName(), 213 - time() - $ttl); 214 - 215 - return $conn_w->getAffectedRows(); 216 - } 217 - 218 - private function collectExpiredFiles() { 219 - $files = id(new PhabricatorFile())->loadAllWhere('ttl < %d LIMIT 100', 220 - time()); 221 - 222 - foreach ($files as $file) { 223 - $file->delete(); 224 - } 225 - 226 - return count($files); 227 - } 228 - 229 - private function collectExpiredConduitLogs() { 230 - $key = 'gcdaemon.ttl.conduit-logs'; 231 - $ttl = PhabricatorEnv::getEnvConfig($key); 232 - if ($ttl <= 0) { 233 - return 0; 234 - } 235 - 236 - $table = new PhabricatorConduitMethodCallLog(); 237 - $conn_w = $table->establishConnection('w'); 238 - queryfx( 239 - $conn_w, 240 - 'DELETE FROM %T WHERE dateCreated < %d 241 - ORDER BY dateCreated ASC LIMIT 100', 242 - $table->getTableName(), 243 - time() - $ttl); 244 - 245 - return $conn_w->getAffectedRows(); 246 - } 247 - 248 - private function collectExpiredConduitConnections() { 249 - $key = 'gcdaemon.ttl.conduit-logs'; 250 - $ttl = PhabricatorEnv::getEnvConfig($key); 251 - if ($ttl <= 0) { 252 - return 0; 253 - } 254 - 255 - $table = new PhabricatorConduitConnectionLog(); 256 - $conn_w = $table->establishConnection('w'); 257 - queryfx( 258 - $conn_w, 259 - 'DELETE FROM %T WHERE dateCreated < %d 260 - ORDER BY dateCreated ASC LIMIT 100', 261 - $table->getTableName(), 262 - time() - $ttl); 263 - 264 - return $conn_w->getAffectedRows(); 265 36 } 266 37 267 38 }