Page MenuHomePhabricator

D18506.id44441.diff
No OneTemporary

D18506.id44441.diff

diff --git a/src/applications/project/query/PhabricatorProjectQuery.php b/src/applications/project/query/PhabricatorProjectQuery.php
--- a/src/applications/project/query/PhabricatorProjectQuery.php
+++ b/src/applications/project/query/PhabricatorProjectQuery.php
@@ -609,7 +609,8 @@
}
if ($this->nameTokens !== null) {
- foreach ($this->nameTokens as $key => $token) {
+ $name_tokens = $this->getNameTokensForQuery($this->nameTokens);
+ foreach ($name_tokens as $key => $token) {
$token_table = 'token_'.$key;
$joins[] = qsprintf(
$conn,
@@ -797,4 +798,22 @@
}
}
+ private function getNameTokensForQuery(array $tokens) {
+ // When querying for projects by name, only actually search for the five
+ // longest tokens. MySQL can get grumpy with a large number of JOINs
+ // with LIKEs and queries for more than 5 tokens are essentially never
+ // legitimate searches for projects, but users copy/pasting nonsense.
+ // See also PHI47.
+
+ $length_map = array();
+ foreach ($tokens as $token) {
+ $length_map[$token] = strlen($token);
+ }
+ arsort($length_map);
+
+ $length_map = array_slice($length_map, 0, 5, true);
+
+ return array_keys($length_map);
+ }
+
}

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 3:58 AM (16 h, 29 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6778348
Default Alt Text
D18506.id44441.diff (1 KB)

Event Timeline