Page MenuHomePhabricator

D13111.diff
No OneTemporary

D13111.diff

diff --git a/src/applications/search/engine/PhabricatorElasticSearchEngine.php b/src/applications/search/engine/PhabricatorElasticSearchEngine.php
--- a/src/applications/search/engine/PhabricatorElasticSearchEngine.php
+++ b/src/applications/search/engine/PhabricatorElasticSearchEngine.php
@@ -121,6 +121,18 @@
return $doc;
}
+ public function removeDocument($phid) {
+ $type = phid_get_type($phid);
+
+ try {
+ $this->executeRequest("/{$type}/{$phid}/", array(), 'DELETE');
+ } catch (HTTPFutureResponseStatus $ex) {
+ if ($ex->getStatusCode() != 404) {
+ throw $ex;
+ }
+ }
+ }
+
private function buildSpec(PhabricatorSavedQuery $query) {
$spec = array();
$filter = array();
diff --git a/src/applications/search/engine/PhabricatorMySQLSearchEngine.php b/src/applications/search/engine/PhabricatorMySQLSearchEngine.php
--- a/src/applications/search/engine/PhabricatorMySQLSearchEngine.php
+++ b/src/applications/search/engine/PhabricatorMySQLSearchEngine.php
@@ -151,6 +151,30 @@
return $adoc;
}
+ public function removeDocument($phid) {
+ $table = new PhabricatorSearchDocument();
+ $conn_w = $table->establishConnection('w');
+
+ queryfx(
+ $conn_w,
+ 'DELETE FROM %T WHERE phid = %s',
+ $table->getTableName(),
+ $phid);
+
+ queryfx(
+ $conn_w,
+ 'DELETE FROM %T WHERE phid = %s',
+ id(new PhabricatorSearchDocumentField())->getTableName(),
+ $phid);
+
+ queryfx(
+ $conn_w,
+ 'DELETE FROM %T WHERE phid = %s OR relatedPHID = %s',
+ id(new PhabricatorSearchDocumentRelationship())->getTableName(),
+ $phid,
+ $phid);
+ }
+
public function executeSearch(PhabricatorSavedQuery $query) {
$where = array();
$join = array();
diff --git a/src/applications/search/engine/PhabricatorSearchEngine.php b/src/applications/search/engine/PhabricatorSearchEngine.php
--- a/src/applications/search/engine/PhabricatorSearchEngine.php
+++ b/src/applications/search/engine/PhabricatorSearchEngine.php
@@ -69,6 +69,14 @@
abstract public function reconstructDocument($phid);
/**
+ * Remove the document for a given PHID.
+ *
+ * @param phid Document PHID to remove.
+ * @return void
+ */
+ abstract public function removeDocument($phid);
+
+ /**
* Execute a search query.
*
* @param PhabricatorSavedQuery A query to execute.
diff --git a/src/applications/system/engine/PhabricatorDestructionEngine.php b/src/applications/system/engine/PhabricatorDestructionEngine.php
--- a/src/applications/system/engine/PhabricatorDestructionEngine.php
+++ b/src/applications/system/engine/PhabricatorDestructionEngine.php
@@ -67,7 +67,7 @@
$transcript->destroyObjectPermanently($this);
}
- // TODO: Remove stuff from search indexes?
+ $this->destroySearchIndexes($object_phid);
if ($object instanceof PhabricatorFlaggableInterface) {
$flags = id(new PhabricatorFlag())->loadAllWhere(
@@ -148,4 +148,12 @@
$object_phid);
}
+ private function destroySearchIndexes($object_phid) {
+ $engines = PhabricatorSearchEngine::loadActiveEngines();
+
+ foreach ($engines as $engine) {
+ $engine->removeDocument($object_phid);
+ }
+ }
+
}

File Metadata

Mime Type
text/plain
Expires
Thu, May 9, 4:53 PM (3 w, 2 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6275217
Default Alt Text
D13111.diff (3 KB)

Event Timeline