Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/query/PhabricatorProjectQuery.php
| Show First 20 Lines • Show All 603 Lines • ▼ Show 20 Lines | protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { | ||||
| if ($this->slugs !== null) { | if ($this->slugs !== null) { | ||||
| $joins[] = qsprintf( | $joins[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'JOIN %T slug on slug.projectPHID = p.phid', | 'JOIN %T slug on slug.projectPHID = p.phid', | ||||
| id(new PhabricatorProjectSlug())->getTableName()); | id(new PhabricatorProjectSlug())->getTableName()); | ||||
| } | } | ||||
| if ($this->nameTokens !== null) { | 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; | $token_table = 'token_'.$key; | ||||
| $joins[] = qsprintf( | $joins[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'JOIN %T %T ON %T.projectID = p.id AND %T.token LIKE %>', | 'JOIN %T %T ON %T.projectID = p.id AND %T.token LIKE %>', | ||||
| PhabricatorProject::TABLE_DATASOURCE_TOKEN, | PhabricatorProject::TABLE_DATASOURCE_TOKEN, | ||||
| $token_table, | $token_table, | ||||
| $token_table, | $token_table, | ||||
| $token_table, | $token_table, | ||||
| ▲ Show 20 Lines • Show All 171 Lines • ▼ Show 20 Lines | if ($this->needSlugs) { | ||||
| $slug_groups = mgroup($slugs, 'getProjectPHID'); | $slug_groups = mgroup($slugs, 'getProjectPHID'); | ||||
| foreach ($projects as $project) { | foreach ($projects as $project) { | ||||
| $project_slugs = idx($slug_groups, $project->getPHID(), array()); | $project_slugs = idx($slug_groups, $project->getPHID(), array()); | ||||
| $project->attachSlugs($project_slugs); | $project->attachSlugs($project_slugs); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| 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); | |||||
| } | |||||
| } | } | ||||