Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / search / garbagecollector / PhabricatorSearchFerretNgramGarbageCollector.php
blobf2c43743f6c5b30b6ace27f74b5dd2611caae4c3
1 <?php
3 final class PhabricatorSearchFerretNgramGarbageCollector
4 extends PhabricatorGarbageCollector {
6 const COLLECTORCONST = 'search.ferret.ngram';
8 public function getCollectorName() {
9 return pht('Ferret Engine Ngrams');
12 public function hasAutomaticPolicy() {
13 return true;
16 protected function collectGarbage() {
17 $all_objects = id(new PhutilClassMapQuery())
18 ->setAncestorClass('PhabricatorFerretInterface')
19 ->execute();
21 $did_collect = false;
22 foreach ($all_objects as $object) {
23 $engine = $object->newFerretEngine();
24 $conn = $object->establishConnection('w');
26 $ngram_row = queryfx_one(
27 $conn,
28 'SELECT ngram FROM %T WHERE needsCollection = 1 LIMIT 1',
29 $engine->getCommonNgramsTableName());
30 if (!$ngram_row) {
31 continue;
34 $ngram = $ngram_row['ngram'];
36 queryfx(
37 $conn,
38 'DELETE FROM %T WHERE ngram = %s',
39 $engine->getNgramsTableName(),
40 $ngram);
42 queryfx(
43 $conn,
44 'UPDATE %T SET needsCollection = 0 WHERE ngram = %s',
45 $engine->getCommonNgramsTableName(),
46 $ngram);
48 $did_collect = true;
49 break;
52 return $did_collect;