Differential D19790 Diff 47258 src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/query/policy/PhabricatorCursorPagedPolicyAwareQuery.php
| Show First 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | protected function loadStandardPageRowsWithConnection( | ||||
| return $rows; | return $rows; | ||||
| } | } | ||||
| protected function buildStandardPageQuery( | protected function buildStandardPageQuery( | ||||
| AphrontDatabaseConnection $conn, | AphrontDatabaseConnection $conn, | ||||
| $table_name) { | $table_name) { | ||||
| $table_alias = $this->getPrimaryTableAlias(); | |||||
| if ($table_alias === null) { | |||||
| $table_alias = qsprintf($conn, ''); | |||||
| } else { | |||||
| $table_alias = qsprintf($conn, '%T', $table_alias); | |||||
| } | |||||
| return qsprintf( | return qsprintf( | ||||
| $conn, | $conn, | ||||
| '%Q FROM %T %Q %Q %Q %Q %Q %Q %Q', | '%Q FROM %T %Q %Q %Q %Q %Q %Q %Q', | ||||
| $this->buildSelectClause($conn), | $this->buildSelectClause($conn), | ||||
| $table_name, | $table_name, | ||||
| (string)$this->getPrimaryTableAlias(), | $table_alias, | ||||
| $this->buildJoinClause($conn), | $this->buildJoinClause($conn), | ||||
| $this->buildWhereClause($conn), | $this->buildWhereClause($conn), | ||||
| $this->buildGroupClause($conn), | $this->buildGroupClause($conn), | ||||
| $this->buildHavingClause($conn), | $this->buildHavingClause($conn), | ||||
| $this->buildOrderClause($conn), | $this->buildOrderClause($conn), | ||||
| $this->buildLimitClause($conn)); | $this->buildLimitClause($conn)); | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 280 Lines • ▼ Show 20 Lines | if ($this->beforeID !== null) { | ||||
| $cursor = $this->beforeID; | $cursor = $this->beforeID; | ||||
| $reversed = true; | $reversed = true; | ||||
| } else if ($this->afterID !== null) { | } else if ($this->afterID !== null) { | ||||
| $cursor = $this->afterID; | $cursor = $this->afterID; | ||||
| $reversed = false; | $reversed = false; | ||||
| } else { | } else { | ||||
| // No paging is being applied to this query so we do not need to | // No paging is being applied to this query so we do not need to | ||||
| // construct a paging clause. | // construct a paging clause. | ||||
| return ''; | return qsprintf($conn, ''); | ||||
| } | } | ||||
| $keys = array(); | $keys = array(); | ||||
| foreach ($vector as $order) { | foreach ($vector as $order) { | ||||
| $keys[] = $order->getOrderKey(); | $keys[] = $order->getOrderKey(); | ||||
| } | } | ||||
| $value_map = $this->getPagingValueMap($cursor, $keys); | $value_map = $this->getPagingValueMap($cursor, $keys); | ||||
| ▲ Show 20 Lines • Show All 213 Lines • ▼ Show 20 Lines | foreach ($columns as $key => $column) { | ||||
| } | } | ||||
| } | } | ||||
| if ($value !== null) { | if ($value !== null) { | ||||
| $parts[] = qsprintf( | $parts[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| '%Q %Q %Q', | '%Q %Q %Q', | ||||
| $field, | $field, | ||||
| $reverse ? '>' : '<', | $reverse ? qsprintf($conn, '>') : qsprintf($conn, '<'), | ||||
| $value); | $value); | ||||
| } | } | ||||
| if ($parts) { | if ($parts) { | ||||
| if (count($parts) > 1) { | $clause[] = qsprintf($conn, '%LO', $parts); | ||||
| $clause[] = '('.implode(') OR (', $parts).')'; | |||||
| } else { | |||||
| $clause[] = head($parts); | |||||
| } | |||||
| } | } | ||||
| if ($clause) { | if ($clause) { | ||||
| if (count($clause) > 1) { | $clauses[] = qsprintf($conn, '%LA', $clause); | ||||
| $clauses[] = '('.implode(') AND (', $clause).')'; | |||||
| } else { | |||||
| $clauses[] = head($clause); | |||||
| } | |||||
| } | } | ||||
| if ($value === null) { | if ($value === null) { | ||||
| $accumulated[] = qsprintf( | $accumulated[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| '%Q IS NULL', | '%Q IS NULL', | ||||
| $field); | $field); | ||||
| } else { | } else { | ||||
| $accumulated[] = qsprintf( | $accumulated[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| '%Q = %Q', | '%Q = %Q', | ||||
| $field, | $field, | ||||
| $value); | $value); | ||||
| } | } | ||||
| } | } | ||||
| return '('.implode(') OR (', $clauses).')'; | if ($clauses) { | ||||
| return qsprintf($conn, '%LO', $clauses); | |||||
| } | |||||
| return qsprintf($conn, ''); | |||||
| } | } | ||||
| /* -( Result Ordering )---------------------------------------------------- */ | /* -( Result Ordering )---------------------------------------------------- */ | ||||
| /** | /** | ||||
| * Select a result ordering. | * Select a result ordering. | ||||
| ▲ Show 20 Lines • Show All 609 Lines • ▼ Show 20 Lines | /* -( Application Search )------------------------------------------------- */ | ||||
| */ | */ | ||||
| protected function buildApplicationSearchGroupClause( | protected function buildApplicationSearchGroupClause( | ||||
| AphrontDatabaseConnection $conn) { | AphrontDatabaseConnection $conn) { | ||||
| if ($this->getApplicationSearchMayJoinMultipleRows()) { | if ($this->getApplicationSearchMayJoinMultipleRows()) { | ||||
| return qsprintf( | return qsprintf( | ||||
| $conn, | $conn, | ||||
| 'GROUP BY %Q', | 'GROUP BY %Q', | ||||
| $this->getApplicationSearchObjectPHIDColumn()); | $this->getApplicationSearchObjectPHIDColumn($conn)); | ||||
| } else { | } else { | ||||
| return qsprintf($conn, ''); | return qsprintf($conn, ''); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Construct a JOIN clause appropriate for applying ApplicationSearch | * Construct a JOIN clause appropriate for applying ApplicationSearch | ||||
| * constraints. | * constraints. | ||||
| * | * | ||||
| * @param AphrontDatabaseConnection Connection executing the query. | * @param AphrontDatabaseConnection Connection executing the query. | ||||
| * @return string Join clause. | * @return string Join clause. | ||||
| * @task appsearch | * @task appsearch | ||||
| */ | */ | ||||
| protected function buildApplicationSearchJoinClause( | protected function buildApplicationSearchJoinClause( | ||||
| AphrontDatabaseConnection $conn) { | AphrontDatabaseConnection $conn) { | ||||
| $joins = array(); | $joins = array(); | ||||
| foreach ($this->applicationSearchConstraints as $key => $constraint) { | foreach ($this->applicationSearchConstraints as $key => $constraint) { | ||||
| $table = $constraint['table']; | $table = $constraint['table']; | ||||
| $alias = $constraint['alias']; | $alias = $constraint['alias']; | ||||
| $index = $constraint['index']; | $index = $constraint['index']; | ||||
| $cond = $constraint['cond']; | $cond = $constraint['cond']; | ||||
| $phid_column = $this->getApplicationSearchObjectPHIDColumn(); | $phid_column = $this->getApplicationSearchObjectPHIDColumn($conn); | ||||
| switch ($cond) { | switch ($cond) { | ||||
| case '=': | case '=': | ||||
| // Figure out whether we need to do a LEFT JOIN or not. We need to | // Figure out whether we need to do a LEFT JOIN or not. We need to | ||||
| // LEFT JOIN if we're going to select "IS NULL" rows. | // LEFT JOIN if we're going to select "IS NULL" rows. | ||||
| $join_type = 'JOIN'; | $join_type = qsprintf($conn, 'JOIN'); | ||||
| foreach ($constraint['constraints'] as $query_constraint) { | foreach ($constraint['constraints'] as $query_constraint) { | ||||
| $op = $query_constraint->getOperator(); | $op = $query_constraint->getOperator(); | ||||
| if ($op === PhabricatorQueryConstraint::OPERATOR_NULL) { | if ($op === PhabricatorQueryConstraint::OPERATOR_NULL) { | ||||
| $join_type = 'LEFT JOIN'; | $join_type = qsprintf($conn, 'LEFT JOIN'); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| $joins[] = qsprintf( | $joins[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| '%Q %T %T ON %T.objectPHID = %Q | '%Q %T %T ON %T.objectPHID = %Q | ||||
| AND %T.indexKey = %s', | AND %T.indexKey = %s', | ||||
| ▲ Show 20 Lines • Show All 1,072 Lines • ▼ Show 20 Lines | foreach ($this->edgeLogicConstraints as $type => $constraints) { | ||||
| break; | break; | ||||
| case PhabricatorQueryConstraint::OPERATOR_ANCESTOR: | case PhabricatorQueryConstraint::OPERATOR_ANCESTOR: | ||||
| case PhabricatorQueryConstraint::OPERATOR_AND: | case PhabricatorQueryConstraint::OPERATOR_AND: | ||||
| case PhabricatorQueryConstraint::OPERATOR_OR: | case PhabricatorQueryConstraint::OPERATOR_OR: | ||||
| // If we're including results with no matches, we have to degrade | // If we're including results with no matches, we have to degrade | ||||
| // this to a LEFT join. We'll use WHERE to select matching rows | // this to a LEFT join. We'll use WHERE to select matching rows | ||||
| // later. | // later. | ||||
| if ($has_null) { | if ($has_null) { | ||||
| $join_type = 'LEFT'; | $join_type = qsprintf($conn, 'LEFT'); | ||||
| } else { | } else { | ||||
| $join_type = ''; | $join_type = qsprintf($conn, ''); | ||||
| } | } | ||||
| $joins[] = qsprintf( | $joins[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| '%Q JOIN %T %T ON %Q = %T.src AND %T.type = %d | '%Q JOIN %T %T ON %Q = %T.src AND %T.type = %d | ||||
| AND %T.dst IN (%Ls)', | AND %T.dst IN (%Ls)', | ||||
| $join_type, | $join_type, | ||||
| $edge_table, | $edge_table, | ||||
| ▲ Show 20 Lines • Show All 456 Lines • ▼ Show 20 Lines | if (!$space_phids && !$include_null) { | ||||
| 'is constrained to.')); | 'is constrained to.')); | ||||
| } | } | ||||
| } | } | ||||
| $alias = $this->getPrimaryTableAlias(); | $alias = $this->getPrimaryTableAlias(); | ||||
| if ($alias) { | if ($alias) { | ||||
| $col = qsprintf($conn, '%T.spacePHID', $alias); | $col = qsprintf($conn, '%T.spacePHID', $alias); | ||||
| } else { | } else { | ||||
| $col = 'spacePHID'; | $col = qsprintf($conn, 'spacePHID'); | ||||
| } | } | ||||
| if ($space_phids && $include_null) { | if ($space_phids && $include_null) { | ||||
| return qsprintf( | return qsprintf( | ||||
| $conn, | $conn, | ||||
| '(%Q IN (%Ls) OR %Q IS NULL)', | '(%Q IN (%Ls) OR %Q IS NULL)', | ||||
| $col, | $col, | ||||
| $space_phids, | $space_phids, | ||||
| Show All 16 Lines | |||||