Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13997685
D11042.id26518.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D11042.id26518.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2536,6 +2536,7 @@
'PhabricatorWorker' => 'infrastructure/daemon/workers/PhabricatorWorker.php',
'PhabricatorWorkerActiveTask' => 'infrastructure/daemon/workers/storage/PhabricatorWorkerActiveTask.php',
'PhabricatorWorkerArchiveTask' => 'infrastructure/daemon/workers/storage/PhabricatorWorkerArchiveTask.php',
+ 'PhabricatorWorkerArchiveTaskQuery' => 'infrastructure/daemon/workers/query/PhabricatorWorkerArchiveTaskQuery.php',
'PhabricatorWorkerDAO' => 'infrastructure/daemon/workers/storage/PhabricatorWorkerDAO.php',
'PhabricatorWorkerLeaseQuery' => 'infrastructure/daemon/workers/query/PhabricatorWorkerLeaseQuery.php',
'PhabricatorWorkerManagementCancelWorkflow' => 'infrastructure/daemon/workers/management/PhabricatorWorkerManagementCancelWorkflow.php',
@@ -5750,6 +5751,7 @@
'PhabricatorWordPressAuthProvider' => 'PhabricatorOAuth2AuthProvider',
'PhabricatorWorkerActiveTask' => 'PhabricatorWorkerTask',
'PhabricatorWorkerArchiveTask' => 'PhabricatorWorkerTask',
+ 'PhabricatorWorkerArchiveTaskQuery' => 'PhabricatorQuery',
'PhabricatorWorkerDAO' => 'PhabricatorLiskDAO',
'PhabricatorWorkerLeaseQuery' => 'PhabricatorQuery',
'PhabricatorWorkerManagementCancelWorkflow' => 'PhabricatorWorkerManagementWorkflow',
diff --git a/src/applications/daemon/controller/PhabricatorDaemonConsoleController.php b/src/applications/daemon/controller/PhabricatorDaemonConsoleController.php
--- a/src/applications/daemon/controller/PhabricatorDaemonConsoleController.php
+++ b/src/applications/daemon/controller/PhabricatorDaemonConsoleController.php
@@ -14,9 +14,9 @@
// but we'd rather show that utilization is too high than too low.
$lease_overhead = 0.250;
- $completed = id(new PhabricatorWorkerArchiveTask())->loadAllWhere(
- 'dateModified > %d',
- $window_start);
+ $completed = id(new PhabricatorWorkerArchiveTaskQuery())
+ ->withDateModifiedSince($window_start)
+ ->execute();
$failed = id(new PhabricatorWorkerActiveTask())->loadAllWhere(
'failureTime > %d',
diff --git a/src/applications/daemon/controller/PhabricatorWorkerTaskDetailController.php b/src/applications/daemon/controller/PhabricatorWorkerTaskDetailController.php
--- a/src/applications/daemon/controller/PhabricatorWorkerTaskDetailController.php
+++ b/src/applications/daemon/controller/PhabricatorWorkerTaskDetailController.php
@@ -15,7 +15,10 @@
$task = id(new PhabricatorWorkerActiveTask())->load($this->id);
if (!$task) {
- $task = id(new PhabricatorWorkerArchiveTask())->load($this->id);
+ $tasks = id(new PhabricatorWorkerArchiveTaskQuery())
+ ->withIDs(array($this->id))
+ ->execute();
+ $task = reset($task);
}
if (!$task) {
diff --git a/src/applications/daemon/garbagecollector/PhabricatorDaemonTaskGarbageCollector.php b/src/applications/daemon/garbagecollector/PhabricatorDaemonTaskGarbageCollector.php
--- a/src/applications/daemon/garbagecollector/PhabricatorDaemonTaskGarbageCollector.php
+++ b/src/applications/daemon/garbagecollector/PhabricatorDaemonTaskGarbageCollector.php
@@ -14,18 +14,16 @@
$data_table = new PhabricatorWorkerTaskData();
$conn_w = $table->establishConnection('w');
- $rows = queryfx_all(
- $conn_w,
- 'SELECT id, dataID FROM %T WHERE dateCreated < %d LIMIT 100',
- $table->getTableName(),
- time() - $ttl);
+ $tasks = id(new PhabricatorWorkerArchiveTaskQuery())
+ ->withDateCreatedBefore(time() - $ttl)
+ ->execute();
- if (!$rows) {
+ if (!$tasks) {
return false;
}
- $data_ids = array_filter(ipull($rows, 'dataID'));
- $task_ids = ipull($rows, 'id');
+ $data_ids = array_filter(mpull($tasks, 'getDataID'));
+ $task_ids = mpull($tasks, 'getID');
$table->openTransaction();
if ($data_ids) {
diff --git a/src/infrastructure/daemon/workers/PhabricatorWorker.php b/src/infrastructure/daemon/workers/PhabricatorWorker.php
--- a/src/infrastructure/daemon/workers/PhabricatorWorker.php
+++ b/src/infrastructure/daemon/workers/PhabricatorWorker.php
@@ -194,9 +194,8 @@
}
}
- $tasks = id(new PhabricatorWorkerArchiveTask())->loadAllWhere(
- 'id IN (%Ld)',
- $task_ids);
+ $tasks = id(new PhabricatorWorkerArchiveTaskQuery())
+ ->withIDs($task_ids);
foreach ($tasks as $task) {
if ($task->getResult() != PhabricatorWorkerArchiveTask::RESULT_SUCCESS) {
diff --git a/src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementWorkflow.php b/src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementWorkflow.php
--- a/src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementWorkflow.php
+++ b/src/infrastructure/daemon/workers/management/PhabricatorWorkerManagementWorkflow.php
@@ -24,9 +24,9 @@
$active_tasks = id(new PhabricatorWorkerActiveTask())->loadAllWhere(
'id IN (%Ls)',
$ids);
- $archive_tasks = id(new PhabricatorWorkerArchiveTask())->loadAllWhere(
- 'id IN (%Ls)',
- $ids);
+ $archive_tasks = id(new PhabricatorWorkerArchiveTaskQuery())
+ ->withIDs($ids)
+ ->execute();
$tasks =
mpull($active_tasks, null, 'getID') +
diff --git a/src/infrastructure/daemon/workers/query/PhabricatorWorkerArchiveTaskQuery.php b/src/infrastructure/daemon/workers/query/PhabricatorWorkerArchiveTaskQuery.php
new file mode 100644
--- /dev/null
+++ b/src/infrastructure/daemon/workers/query/PhabricatorWorkerArchiveTaskQuery.php
@@ -0,0 +1,82 @@
+<?php
+
+final class PhabricatorWorkerArchiveTaskQuery
+ extends PhabricatorQuery {
+
+ private $ids;
+ private $dateModifiedSince;
+ private $dateCreatedBefore;
+ private $limit;
+
+ public function withIDs(array $ids) {
+ $this->ids = $ids;
+ return $this;
+ }
+
+ public function withDateModifiedSince($timestamp) {
+ $this->dateModifiedSince = $timestamp;
+ return $this;
+ }
+
+ public function withDateCreatedBefore($timestamp) {
+ $this->dateCreatedBefore = $timestamp;
+ return $this;
+ }
+
+ public function setLimit($limit) {
+ $this->limit = $limit;
+ return $this;
+ }
+
+ public function execute() {
+
+ $task_table = new PhabricatorWorkerArchiveTask();
+
+ $conn_r = $task_table->establishConnection('r');
+
+ $rows = queryfx_all(
+ $conn_r,
+ 'SELECT * FROM %T %Q %Q',
+ $task_table->getTableName(),
+ $this->buildWhereClause($conn_r),
+ $this->buildLimitClause($conn_r));
+
+ return $task_table->loadAllFromArray($rows);
+ }
+
+ private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
+ $where = array();
+
+ if ($this->ids !== null) {
+ $where[] = qsprintf(
+ $conn_r,
+ 'ids in (%Ld)',
+ $this->ids);
+ }
+
+ if ($this->dateModifiedSince) {
+ $where[] = qsprintf(
+ $conn_r,
+ 'dateModified > %d',
+ $this->dateModifiedSince);
+ }
+
+ if ($this->dateCreatedBefore) {
+ $where[] = qsprintf(
+ $conn_r,
+ 'dateCreated < %d',
+ $this->dateCreatedBefore);
+ }
+
+ return $this->formatWhereClause($where);
+ }
+
+ private function buildLimitClause(AphrontDatabaseConnection $conn_r) {
+ $clause = '';
+ if ($this->limit) {
+ $clause = qsprintf($conn_r, 'LIMIT %d', $this->limit);
+ }
+ return $clause;
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Oct 25, 5:39 AM (3 w, 3 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6747973
Default Alt Text
D11042.id26518.diff (7 KB)
Attached To
Mode
D11042: Daemons - introduce PhabricatorWorkerArchiveTaskQuery
Attached
Detach File
Event Timeline
Log In to Comment