@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Clean up more PonderAnswer cruft

Summary: Ref T2715. Ref T3578. Moves PonderAnswerQuery toward being policy-aware so we can use application PHIDs.

Test Plan: Viewed various Ponder things, voted on answers.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2715, T3578

Differential Revision: https://secure.phabricator.com/D6581

+59 -45
+1 -1
src/applications/ponder/controller/PonderVoteSaveController.php
··· 25 25 } else if ($this->kind == "answer") { 26 26 $target = id(new PonderAnswerQuery()) 27 27 ->setViewer($user) 28 - ->withPHID($phid) 28 + ->withPHIDs(array($phid)) 29 29 ->executeOne(); 30 30 } 31 31
+51 -42
src/applications/ponder/query/PonderAnswerQuery.php
··· 2 2 3 3 final class PonderAnswerQuery extends PhabricatorOffsetPagedQuery { 4 4 5 - private $id; 6 - private $phid; 7 - private $authorPHID; 8 - private $orderNewest; 5 + private $ids; 6 + private $phids; 7 + private $authorPHIDs; 8 + private $questionIDs; 9 9 10 10 private $viewer; 11 11 ··· 22 22 return head($this->execute()); 23 23 } 24 24 25 - public function withID($qid) { 26 - $this->id = $qid; 25 + public function withIDs(array $ids) { 26 + $this->ids = $ids; 27 27 return $this; 28 28 } 29 29 30 - public function withPHID($phid) { 31 - $this->phid = $phid; 30 + public function withPHIDs(array $phids) { 31 + $this->phids = $phids; 32 32 return $this; 33 33 } 34 34 35 - public function withAuthorPHID($phid) { 36 - $this->authorPHID = $phid; 35 + public function withAuthorPHIDs(array $phids) { 36 + $this->authorPHIDs = $phids; 37 37 return $this; 38 38 } 39 39 40 - public function orderByNewest($usethis) { 41 - $this->orderNewest = $usethis; 40 + public function withQuestionIDs(array $ids) { 41 + $this->questionIDs = $ids; 42 42 return $this; 43 43 } 44 44 45 45 private function buildWhereClause($conn_r) { 46 46 $where = array(); 47 - if ($this->id) { 48 - $where[] = qsprintf($conn_r, '(id = %d)', $this->id); 47 + 48 + if ($this->ids) { 49 + $where[] = qsprintf( 50 + $conn_r, 51 + 'id IN (%Ld)', 52 + $this->ids); 49 53 } 50 - if ($this->phid) { 51 - $where[] = qsprintf($conn_r, '(phid = %s)', $this->phid); 54 + 55 + if ($this->phids) { 56 + $where[] = qsprintf( 57 + $conn_r, 58 + 'phid IN (%Ls)', 59 + $this->phids); 52 60 } 53 - if ($this->authorPHID) { 54 - $where[] = qsprintf($conn_r, '(authorPHID = %s)', $this->authorPHID); 61 + 62 + if ($this->authorPHIDs) { 63 + $where[] = qsprintf( 64 + $conn_r, 65 + 'authorPHID IN (%Ls)', 66 + $this->authorPHIDs); 55 67 } 56 68 57 69 return $this->formatWhereClause($where); 58 70 } 59 71 60 72 private function buildOrderByClause($conn_r) { 61 - $order = array(); 62 - if ($this->orderNewest) { 63 - $order[] = qsprintf($conn_r, 'id DESC'); 64 - } 65 - 66 - if (count($order) == 0) { 67 - $order[] = qsprintf($conn_r, 'id ASC'); 68 - } 69 - 70 - return ($order ? 'ORDER BY ' . implode(', ', $order) : ''); 73 + return 'ORDER BY id ASC'; 71 74 } 72 75 73 76 public function execute() { 74 77 $answer = new PonderAnswer(); 75 78 $conn_r = $answer->establishConnection('r'); 76 79 77 - $select = qsprintf( 80 + $data = queryfx_all( 78 81 $conn_r, 79 - 'SELECT r.* FROM %T r', 80 - $answer->getTableName()); 82 + 'SELECT a.* FROM %T a %Q %Q %Q', 83 + $answer->getTableName(), 84 + $this->buildWhereClause($conn_r), 85 + $this->buildOrderByClause($conn_r), 86 + $this->buildLimitClause($conn_r)); 81 87 82 - $where = $this->buildWhereClause($conn_r); 83 - $order_by = $this->buildOrderByClause($conn_r); 84 - $limit = $this->buildLimitClause($conn_r); 88 + $answers = $answer->loadAllFromArray($data); 89 + 90 + if ($answers) { 91 + $questions = id(new PonderQuestionQuery()) 92 + ->setViewer($this->getViewer()) 93 + ->withIDs(mpull($answers, 'getQuestionID')) 94 + ->execute(); 95 + 96 + foreach ($answers as $answer) { 97 + $question = idx($questions, $answer->getQuestionID()); 98 + $answer->attachQuestion($question); 99 + } 100 + } 85 101 86 - return $answer->loadAllFromArray( 87 - queryfx_all( 88 - $conn_r, 89 - '%Q %Q %Q %Q', 90 - $select, 91 - $where, 92 - $order_by, 93 - $limit)); 102 + return $answers; 94 103 } 95 104 }
+7 -2
src/applications/ponder/storage/PonderAnswer.php
··· 14 14 15 15 protected $voteCount; 16 16 private $vote; 17 - private $question = null; 17 + private $question = self::ATTACHABLE; 18 18 private $comments; 19 19 20 + // TODO: Get rid of this method. 20 21 public function setQuestion($question) { 22 + return $this->attachQuestion($question); 23 + } 24 + 25 + public function attachQuestion(PonderQuestion $question = null) { 21 26 $this->question = $question; 22 27 return $this; 23 28 } 24 29 25 30 public function getQuestion() { 26 - return $this->question; 31 + return $this->assertAttached($this->question); 27 32 } 28 33 29 34 public function setUserVote($vote) {