diff --git a/src/applications/herald/controller/transcriptlist/HeraldTranscriptListController.php b/src/applications/herald/controller/transcriptlist/HeraldTranscriptListController.php index 1e07887b4f..db69b1612f 100644 --- a/src/applications/herald/controller/transcriptlist/HeraldTranscriptListController.php +++ b/src/applications/herald/controller/transcriptlist/HeraldTranscriptListController.php @@ -1,134 +1,150 @@ <?php /* * Copyright 2011 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ class HeraldTranscriptListController extends HeraldController { public function processRequest() { $request = $this->getRequest(); + // Get one page of data together with the pager. // Pull these objects manually since the serialized fields are gigantic. $transcript = new HeraldTranscript(); $conn_r = $transcript->establishConnection('r'); $phid = $request->getStr('phid'); $where_clause = ''; if ($phid) { $where_clause = qsprintf( $conn_r, 'WHERE objectPHID = %s', - $phid - ); + $phid); } + $offset = $request->getInt('offset', 0); + $page_size = 100; + $limit_clause = qsprintf( + $conn_r, + 'LIMIT %d, %d', + $offset, $page_size + 1); + $data = queryfx_all( $conn_r, 'SELECT id, objectPHID, time, duration, dryRun FROM %T %Q ORDER BY id DESC - LIMIT 100', + %Q', $transcript->getTableName(), - $where_clause); + $where_clause, + $limit_clause); + + $pager = new AphrontPagerView(); + $pager->getPageSize($page_size); + $pager->setHasMorePages(count($data) == $page_size + 1); + $pager->setOffset($offset); + $pager->setURI($request->getRequestURI(), 'offset'); /* $conn_r = smc_get_db('cdb.herald', 'r'); $page_size = 100; $pager = new SimplePager(); $pager->setPageSize($page_size); $pager->setOffset((((int)$request->getInt('page')) - 1) * $page_size); $pager->order('id', array('id')); $fbid = $request->getInt('fbid'); if ($fbid) { $filter = qsprintf( $conn_r, 'WHERE objectID = %d', $fbid); } else { $filter = ''; } $data = $pager->select( $conn_r, 'id, objectID, time, duration, dryRun FROM transcript %Q', $filter); */ + // Render the table. $handles = array(); if ($data) { $phids = ipull($data, 'objectPHID', 'objectPHID'); $handles = id(new PhabricatorObjectHandleData($phids)) ->loadHandles(); } $rows = array(); foreach ($data as $xscript) { $rows[] = array( date('F jS', $xscript['time']), date('g:i:s A', $xscript['time']), $handles[$xscript['objectPHID']]->renderLink(), $xscript['dryRun'] ? 'Yes' : '', number_format((int)(1000 * $xscript['duration'])).' ms', phutil_render_tag( 'a', array( 'href' => '/herald/transcript/'.$xscript['id'].'/', 'class' => 'button small grey', ), 'View Transcript'), ); } $table = new AphrontTableView($rows); $table->setHeaders( array( 'Date', 'Time', 'Object', 'Dry Run', 'Duration', 'View', )); $table->setColumnClasses( array( '', 'right', 'wide wrap', '', '', 'action', )); - + // Render the whole page. $panel = new AphrontPanelView(); $panel->setHeader('Herald Transcripts'); $panel->appendChild($table); + $panel->appendChild($pager); return $this->buildStandardPageResponse( $panel, array( 'title' => 'Herald Transcripts', 'tab' => 'transcripts', )); } } diff --git a/src/applications/herald/controller/transcriptlist/__init__.php b/src/applications/herald/controller/transcriptlist/__init__.php index 3a574f58ed..13aacd82dc 100644 --- a/src/applications/herald/controller/transcriptlist/__init__.php +++ b/src/applications/herald/controller/transcriptlist/__init__.php @@ -1,21 +1,22 @@ <?php /** * This file is automatically generated. Lint this module to rebuild it. * @generated */ phutil_require_module('phabricator', 'applications/herald/controller/base'); phutil_require_module('phabricator', 'applications/herald/storage/transcript/base'); phutil_require_module('phabricator', 'applications/phid/handle/data'); phutil_require_module('phabricator', 'storage/qsprintf'); phutil_require_module('phabricator', 'storage/queryfx'); +phutil_require_module('phabricator', 'view/control/pager'); phutil_require_module('phabricator', 'view/control/table'); phutil_require_module('phabricator', 'view/layout/panel'); phutil_require_module('phutil', 'markup'); phutil_require_module('phutil', 'utils'); phutil_require_source('HeraldTranscriptListController.php'); diff --git a/src/applications/metamta/controller/list/PhabricatorMetaMTAListController.php b/src/applications/metamta/controller/list/PhabricatorMetaMTAListController.php index 2d93fd140d..be4e328587 100644 --- a/src/applications/metamta/controller/list/PhabricatorMetaMTAListController.php +++ b/src/applications/metamta/controller/list/PhabricatorMetaMTAListController.php @@ -1,86 +1,112 @@ <?php /* * Copyright 2011 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ class PhabricatorMetaMTAListController extends PhabricatorMetaMTAController { public function processRequest() { - $related_phid = $this->getRequest()->getStr('phid'); + // Get a page of mails together with pager. + $request = $this->getRequest(); + $offset = $request->getInt('offset', 0); + $related_phid = $request->getStr('phid'); + + $pager = new AphrontPagerView(); + $pager->setOffset($offset); + $pager->setURI($request->getRequestURI(), 'offset'); + + $mail = new PhabricatorMetaMTAMail(); + $conn_r = $mail->establishConnection('r'); if ($related_phid) { - $mails = id(new PhabricatorMetaMTAMail())->loadAllWhere( - 'relatedPHID = %s ORDER BY id DESC LIMIT 100', + $where_clause = qsprintf( + $conn_r, + 'WHERE relatedPHID = %s', $related_phid); } else { - $mails = id(new PhabricatorMetaMTAMail())->loadAllWhere( - '1 = 1 ORDER BY id DESC LIMIT 100'); + $where_clause = 'WHERE 1 = 1'; } + $data = queryfx_all( + $conn_r, + 'SELECT * FROM %T + %Q + ORDER BY id DESC + LIMIT %d, %d', + $mail->getTableName(), + $where_clause, + $pager->getOffset(), $pager->getPageSize() + 1); + $data = $pager->sliceResults($data); + + $mails = $mail->loadAllFromArray($data); + + // Render the details table. $rows = array(); foreach ($mails as $mail) { $rows[] = array( PhabricatorMetaMTAMail::getReadableStatus($mail->getStatus()), $mail->getRetryCount(), ($mail->getNextRetry() - time()).' s', date('Y-m-d g:i:s A', $mail->getDateCreated()), (time() - $mail->getDateModified()).' s', phutil_escape_html($mail->getSubject()), phutil_render_tag( 'a', array( 'class' => 'button small grey', 'href' => '/mail/view/'.$mail->getID().'/', ), 'View'), ); } $table = new AphrontTableView($rows); $table->setHeaders( array( 'Status', 'Retry', 'Next', 'Created', 'Updated', 'Subject', '', )); $table->setColumnClasses( array( null, null, null, null, null, 'wide', 'action', )); + // Render the whole page. $panel = new AphrontPanelView(); $panel->appendChild($table); $panel->setHeader('MetaMTA Messages'); $panel->setCreateButton('Send New Message', '/mail/send/'); + $panel->appendChild($pager); return $this->buildStandardPageResponse( $panel, array( 'title' => 'MetaMTA', 'tab' => 'queue', )); } } diff --git a/src/applications/metamta/controller/list/__init__.php b/src/applications/metamta/controller/list/__init__.php index 79f3117912..49a41c7b7f 100644 --- a/src/applications/metamta/controller/list/__init__.php +++ b/src/applications/metamta/controller/list/__init__.php @@ -1,18 +1,20 @@ <?php /** * This file is automatically generated. Lint this module to rebuild it. * @generated */ phutil_require_module('phabricator', 'applications/metamta/controller/base'); phutil_require_module('phabricator', 'applications/metamta/storage/mail'); +phutil_require_module('phabricator', 'storage/qsprintf'); +phutil_require_module('phabricator', 'storage/queryfx'); +phutil_require_module('phabricator', 'view/control/pager'); phutil_require_module('phabricator', 'view/control/table'); phutil_require_module('phabricator', 'view/layout/panel'); phutil_require_module('phutil', 'markup'); -phutil_require_module('phutil', 'utils'); phutil_require_source('PhabricatorMetaMTAListController.php');