Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diviner/query/DivinerAtomQuery.php
| Show First 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | final class DivinerAtomQuery extends PhabricatorCursorPagedPolicyAwareQuery { | ||||
| } | } | ||||
| public function needRepositories($need_repositories) { | public function needRepositories($need_repositories) { | ||||
| $this->needRepositories = $need_repositories; | $this->needRepositories = $need_repositories; | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| protected function loadPage() { | protected function loadPage() { | ||||
| $table = new DivinerLiveSymbol(); | return $this->loadStandardPage(new DivinerLiveSymbol()); | ||||
| $conn_r = $table->establishConnection('r'); | |||||
| $data = queryfx_all( | |||||
| $conn_r, | |||||
| 'SELECT * FROM %T %Q %Q %Q', | |||||
| $table->getTableName(), | |||||
| $this->buildWhereClause($conn_r), | |||||
| $this->buildOrderClause($conn_r), | |||||
| $this->buildLimitClause($conn_r)); | |||||
| return $table->loadAllFromArray($data); | |||||
| } | } | ||||
| protected function willFilterPage(array $atoms) { | protected function willFilterPage(array $atoms) { | ||||
| assert_instances_of($atoms, 'DivinerLiveSymbol'); | assert_instances_of($atoms, 'DivinerLiveSymbol'); | ||||
| $books = array_unique(mpull($atoms, 'getBookPHID')); | $books = array_unique(mpull($atoms, 'getBookPHID')); | ||||
| $books = id(new DivinerBookQuery()) | $books = id(new DivinerBookQuery()) | ||||
| ▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | if ($this->needRepositories) { | ||||
| $atom->attachRepository($repository); | $atom->attachRepository($repository); | ||||
| } | } | ||||
| } | } | ||||
| return $atoms; | return $atoms; | ||||
| } | } | ||||
| protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
| $where = array(); | $where = parent::buildWhereClauseParts($conn); | ||||
| if ($this->ids) { | if ($this->ids) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'id IN (%Ld)', | 'id IN (%Ld)', | ||||
| $this->ids); | $this->ids); | ||||
| } | } | ||||
| if ($this->phids) { | if ($this->phids) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'phid IN (%Ls)', | 'phid IN (%Ls)', | ||||
| $this->phids); | $this->phids); | ||||
| } | } | ||||
| if ($this->bookPHIDs) { | if ($this->bookPHIDs) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'bookPHID IN (%Ls)', | 'bookPHID IN (%Ls)', | ||||
| $this->bookPHIDs); | $this->bookPHIDs); | ||||
| } | } | ||||
| if ($this->types) { | if ($this->types) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'type IN (%Ls)', | 'type IN (%Ls)', | ||||
| $this->types); | $this->types); | ||||
| } | } | ||||
| if ($this->names) { | if ($this->names) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'name IN (%Ls)', | 'name IN (%Ls)', | ||||
| $this->names); | $this->names); | ||||
| } | } | ||||
| if ($this->titles) { | if ($this->titles) { | ||||
| $hashes = array(); | $hashes = array(); | ||||
| foreach ($this->titles as $title) { | foreach ($this->titles as $title) { | ||||
| $slug = DivinerAtomRef::normalizeTitleString($title); | $slug = DivinerAtomRef::normalizeTitleString($title); | ||||
| $hash = PhabricatorHash::digestForIndex($slug); | $hash = PhabricatorHash::digestForIndex($slug); | ||||
| $hashes[] = $hash; | $hashes[] = $hash; | ||||
| } | } | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'titleSlugHash in (%Ls)', | 'titleSlugHash in (%Ls)', | ||||
| $hashes); | $hashes); | ||||
| } | } | ||||
| if ($this->contexts) { | if ($this->contexts) { | ||||
| $with_null = false; | $with_null = false; | ||||
| $contexts = $this->contexts; | $contexts = $this->contexts; | ||||
| foreach ($contexts as $key => $value) { | foreach ($contexts as $key => $value) { | ||||
| if ($value === null) { | if ($value === null) { | ||||
| unset($contexts[$key]); | unset($contexts[$key]); | ||||
| $with_null = true; | $with_null = true; | ||||
| continue; | continue; | ||||
| } | } | ||||
| } | } | ||||
| if ($contexts && $with_null) { | if ($contexts && $with_null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'context IN (%Ls) OR context IS NULL', | 'context IN (%Ls) OR context IS NULL', | ||||
| $contexts); | $contexts); | ||||
| } else if ($contexts) { | } else if ($contexts) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'context IN (%Ls)', | 'context IN (%Ls)', | ||||
| $contexts); | $contexts); | ||||
| } else if ($with_null) { | } else if ($with_null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'context IS NULL'); | 'context IS NULL'); | ||||
| } | } | ||||
| } | } | ||||
| if ($this->indexes) { | if ($this->indexes) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'atomIndex IN (%Ld)', | 'atomIndex IN (%Ld)', | ||||
| $this->indexes); | $this->indexes); | ||||
| } | } | ||||
| if ($this->isDocumentable !== null) { | if ($this->isDocumentable !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'isDocumentable = %d', | 'isDocumentable = %d', | ||||
| (int)$this->isDocumentable); | (int)$this->isDocumentable); | ||||
| } | } | ||||
| if ($this->isGhost !== null) { | if ($this->isGhost !== null) { | ||||
| if ($this->isGhost) { | if ($this->isGhost) { | ||||
| $where[] = qsprintf($conn_r, 'graphHash IS NULL'); | $where[] = qsprintf($conn, 'graphHash IS NULL'); | ||||
| } else { | } else { | ||||
| $where[] = qsprintf($conn_r, 'graphHash IS NOT NULL'); | $where[] = qsprintf($conn, 'graphHash IS NOT NULL'); | ||||
| } | } | ||||
| } | } | ||||
| if ($this->nodeHashes) { | if ($this->nodeHashes) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'nodeHash IN (%Ls)', | 'nodeHash IN (%Ls)', | ||||
| $this->nodeHashes); | $this->nodeHashes); | ||||
| } | } | ||||
| if ($this->nameContains) { | if ($this->nameContains) { | ||||
| // NOTE: This `CONVERT()` call makes queries case-insensitive, since | // NOTE: This `CONVERT()` call makes queries case-insensitive, since | ||||
| // the column has binary collation. Eventually, this should move into | // the column has binary collation. Eventually, this should move into | ||||
| // fulltext. | // fulltext. | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'CONVERT(name USING utf8) LIKE %~', | 'CONVERT(name USING utf8) LIKE %~', | ||||
| $this->nameContains); | $this->nameContains); | ||||
| } | } | ||||
| if ($this->repositoryPHIDs) { | if ($this->repositoryPHIDs) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn_r, | $conn, | ||||
| 'repositoryPHID IN (%Ls)', | 'repositoryPHID IN (%Ls)', | ||||
| $this->repositoryPHIDs); | $this->repositoryPHIDs); | ||||
| } | } | ||||
| $where[] = $this->buildPagingClause($conn_r); | $where[] = $this->buildPagingClause($conn); | ||||
| return $this->formatWhereClause($where); | return $where; | ||||
| } | } | ||||
| /** | /** | ||||
| * Walk a list of atoms and collect all the node hashes of the atoms' | * Walk a list of atoms and collect all the node hashes of the atoms' | ||||
| * children. When recursing, also walk up the tree and collect children of | * children. When recursing, also walk up the tree and collect children of | ||||
| * atoms they extend. | * atoms they extend. | ||||
| * | * | ||||
| * @param list<DivinerLiveSymbol> List of symbols to collect child hashes of. | * @param list<DivinerLiveSymbol> List of symbols to collect child hashes of. | ||||
| ▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines | |||||