diff --git a/src/applications/feed/query/PhabricatorFeedQuery.php b/src/applications/feed/query/PhabricatorFeedQuery.php index 7e610e4483..a0851aeca0 100644 --- a/src/applications/feed/query/PhabricatorFeedQuery.php +++ b/src/applications/feed/query/PhabricatorFeedQuery.php @@ -1,110 +1,126 @@ filterPHIDs = $phids; return $this; } public function withChronologicalKeys(array $keys) { $this->chronologicalKeys = $keys; return $this; } protected function loadPage() { $story_table = new PhabricatorFeedStoryData(); $conn = $story_table->establishConnection('r'); $data = queryfx_all( $conn, 'SELECT story.* FROM %T story %Q %Q %Q %Q %Q', $story_table->getTableName(), $this->buildJoinClause($conn), $this->buildWhereClause($conn), $this->buildGroupClause($conn), $this->buildOrderClause($conn), $this->buildLimitClause($conn)); return $data; } protected function willFilterPage(array $data) { return PhabricatorFeedStory::loadAllFromRows($data, $this->getViewer()); } private function buildJoinClause(AphrontDatabaseConnection $conn_r) { // NOTE: We perform this join unconditionally (even if we have no filter // PHIDs) to omit rows which have no story references. These story data // rows are notifications or realtime alerts. $ref_table = new PhabricatorFeedStoryReference(); return qsprintf( $conn_r, 'JOIN %T ref ON ref.chronologicalKey = story.chronologicalKey', $ref_table->getTableName()); } private function buildWhereClause(AphrontDatabaseConnection $conn_r) { $where = array(); if ($this->filterPHIDs) { $where[] = qsprintf( $conn_r, 'ref.objectPHID IN (%Ls)', $this->filterPHIDs); } if ($this->chronologicalKeys) { // NOTE: We want to use integers in the query so we can take advantage // of keys, but can't use %d on 32-bit systems. Make sure all the keys // are integers and then format them raw. $keys = $this->chronologicalKeys; foreach ($keys as $key) { if (!ctype_digit($key)) { throw new Exception("Key '{$key}' is not a valid chronological key!"); } } $where[] = qsprintf( $conn_r, 'ref.chronologicalKey IN (%Q)', implode(', ', $keys)); } $where[] = $this->buildPagingClause($conn_r); return $this->formatWhereClause($where); } private function buildGroupClause(AphrontDatabaseConnection $conn_r) { if ($this->filterPHIDs) { return qsprintf($conn_r, 'GROUP BY ref.chronologicalKey'); } else { return qsprintf($conn_r, 'GROUP BY story.chronologicalKey'); } } - protected function getPagingColumn() { - return ($this->filterPHIDs - ? 'ref.chronologicalKey' - : 'story.chronologicalKey'); + protected function getDefaultOrderVector() { + return array('key'); + } + + public function getOrderableColumns() { + $table = ($this->filterPHIDs ? 'ref' : 'story'); + return array( + 'key' => array( + 'table' => $table, + 'column' => 'chronologicalKey', + 'type' => 'int', + 'unique' => true, + ), + ); + } + + protected function getPagingValueMap($cursor, array $keys) { + return array( + 'key' => $cursor, + ); } protected function getPagingValue($item) { if ($item instanceof PhabricatorFeedStory) { return $item->getChronologicalKey(); } return $item['chronologicalKey']; } public function getQueryApplicationClass() { return 'PhabricatorFeedApplication'; } } diff --git a/src/applications/phlux/query/PhluxVariableQuery.php b/src/applications/phlux/query/PhluxVariableQuery.php index 190b677934..3439ee1d8b 100644 --- a/src/applications/phlux/query/PhluxVariableQuery.php +++ b/src/applications/phlux/query/PhluxVariableQuery.php @@ -1,72 +1,95 @@ ids = $ids; + return $this; + } + public function withPHIDs(array $phids) { $this->phids = $phids; return $this; } public function withKeys(array $keys) { $this->keys = $keys; return $this; } protected function loadPage() { $table = new PhluxVariable(); $conn_r = $table->establishConnection('r'); $rows = 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($rows); } private function buildWhereClause(AphrontDatabaseConnection $conn_r) { $where = array(); - $where[] = $this->buildPagingClause($conn_r); + if ($this->ids !== null) { + $where[] = qsprintf( + $conn_r, + 'id IN (%Ld)', + $this->ids); + } - if ($this->keys) { + if ($this->keys !== null) { $where[] = qsprintf( $conn_r, 'variableKey IN (%Ls)', $this->keys); } - if ($this->phids) { + if ($this->phids !== null) { $where[] = qsprintf( $conn_r, 'phid IN (%Ls)', $this->phids); } + $where[] = $this->buildPagingClause($conn_r); + return $this->formatWhereClause($where); } - protected function getPagingColumn() { - return 'variableKey'; + protected function getDefaultOrderVector() { + return array('key'); } - protected function getPagingValue($result) { - return $result->getVariableKey(); + public function getOrderableColumns() { + return array( + 'key' => array( + 'column' => 'variableKey', + 'type' => 'string', + 'reverse' => true, + 'unique' => true, + ), + ); } - protected function getReversePaging() { - return true; + protected function getPagingValueMap($cursor, array $keys) { + $object = $this->loadCursorObject($cursor); + return array( + 'key' => $object->getVariableKey(), + ); } public function getQueryApplicationClass() { return 'PhabricatorPhluxApplication'; } }