From ef106d2979352849575141b5cfbc3ffb6ec2d4a4 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 19 Jan 2015 16:55:52 -0800 Subject: [PATCH] Add order-by-ID to PhabricatorWorkerTriggerQuery Summary: Ref T6881. By design, the EXECUTION order only selects tasks which have been scheduled (since it performs a JOIN). This is inconsistent with other queries and problematic for withID/withPHID queries which may want to select an unscheduled task. Switch to standard ID ordering by default. Test Plan: - Instances console now finds unscheduled triggers. - Verified that all existing queries specify an explicit order. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T6881 Differential Revision: https://secure.phabricator.com/D11436 --- .../query/PhabricatorWorkerTriggerQuery.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/infrastructure/daemon/workers/query/PhabricatorWorkerTriggerQuery.php b/src/infrastructure/daemon/workers/query/PhabricatorWorkerTriggerQuery.php index 529528b29b..72da00bb68 100644 --- a/src/infrastructure/daemon/workers/query/PhabricatorWorkerTriggerQuery.php +++ b/src/infrastructure/daemon/workers/query/PhabricatorWorkerTriggerQuery.php @@ -3,6 +3,7 @@ final class PhabricatorWorkerTriggerQuery extends PhabricatorOffsetPagedQuery { + const ORDER_ID = 'id'; const ORDER_EXECUTION = 'execution'; const ORDER_VERSION = 'version'; @@ -14,7 +15,7 @@ final class PhabricatorWorkerTriggerQuery private $nextEpochMax; private $needEvents; - private $order = self::ORDER_EXECUTION; + private $order = self::ORDER_ID; public function withIDs(array $ids) { $this->ids = $ids; @@ -43,6 +44,16 @@ final class PhabricatorWorkerTriggerQuery return $this; } + /** + * Set the result order. + * + * Note that using `ORDER_EXECUTION` will also filter results to include only + * triggers which have been scheduled to execute. You should not use this + * ordering when querying for specific triggers, e.g. by ID or PHID. + * + * @param const Result order. + * @return this + */ public function setOrder($order) { $this->order = $order; return $this; @@ -185,6 +196,10 @@ final class PhabricatorWorkerTriggerQuery private function buildOrderClause(AphrontDatabaseConnection $conn_r) { switch ($this->order) { + case self::ORDER_ID: + return qsprintf( + $conn_r, + 'ORDER BY id DESC'); case self::ORDER_EXECUTION: return qsprintf( $conn_r,