@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.

move ponder writes into editors; better search indexing

Summary:
* Moved the remaining `->save()` calls into editors
* for the `PonderQuestion`, separate `attachRelated` (needed for
indexing and viewing) from `attachVotes` (needed for viewing
but not indexing)
* Update the indexer to include comment and answer content
in the search index.

Test Plan:
Stuff works as before. Also: add a comment or answer with some
easily-identifiable text and search for it; observe that
it gets indexed appropriately.

Reviewers: epriestley, nh, vrana

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T1869

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

+151 -32
+2
src/__phutil_library_map__.php
··· 1201 1201 'PonderAnswerSaveController' => 'applications/ponder/controller/PonderAnswerSaveController.php', 1202 1202 'PonderAnswerViewController' => 'applications/ponder/controller/PonderAnswerViewController.php', 1203 1203 'PonderComment' => 'applications/ponder/storage/PonderComment.php', 1204 + 'PonderCommentEditor' => 'applications/ponder/editor/PonderCommentEditor.php', 1204 1205 'PonderCommentListView' => 'applications/ponder/view/PonderCommentListView.php', 1205 1206 'PonderCommentQuery' => 'applications/ponder/query/PonderCommentQuery.php', 1206 1207 'PonderCommentSaveController' => 'applications/ponder/controller/PonderCommentSaveController.php', ··· 1212 1213 'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php', 1213 1214 'PonderQuestionAskController' => 'applications/ponder/controller/PonderQuestionAskController.php', 1214 1215 'PonderQuestionDetailView' => 'applications/ponder/view/PonderQuestionDetailView.php', 1216 + 'PonderQuestionEditor' => 'applications/ponder/editor/PonderQuestionEditor.php', 1215 1217 'PonderQuestionPreviewController' => 'applications/ponder/controller/PonderQuestionPreviewController.php', 1216 1218 'PonderQuestionQuery' => 'applications/ponder/query/PonderQuestionQuery.php', 1217 1219 'PonderQuestionSummaryView' => 'applications/ponder/view/PonderQuestionSummaryView.php',
-2
src/applications/ponder/controller/PonderAnswerSaveController.php
··· 64 64 ->setAnswer($res) 65 65 ->saveAnswer(); 66 66 67 - PhabricatorSearchPonderIndexer::indexQuestion($question); 68 - 69 67 return id(new AphrontRedirectResponse())->setURI( 70 68 id(new PhutilURI('/Q'. $question->getID()))); 71 69 }
+5 -3
src/applications/ponder/controller/PonderCommentSaveController.php
··· 54 54 $res 55 55 ->setContent($content) 56 56 ->setAuthorPHID($user->getPHID()) 57 - ->setTargetPHID($target) 58 - ->save(); 57 + ->setTargetPHID($target); 59 58 60 - PhabricatorSearchPonderIndexer::indexQuestion($question); 59 + id(new PonderCommentEditor()) 60 + ->setQuestion($question) 61 + ->setComment($res) 62 + ->save(); 61 63 62 64 return id(new AphrontRedirectResponse()) 63 65 ->setURI(
+3 -2
src/applications/ponder/controller/PonderQuestionAskController.php
··· 50 50 'ip' => $request->getRemoteAddr(), 51 51 )); 52 52 $question->setContentSource($content_source); 53 - $question->save(); 54 53 55 - PhabricatorSearchPonderIndexer::indexQuestion($question); 54 + id(new PonderQuestionEditor()) 55 + ->setQuestion($question) 56 + ->save(); 56 57 57 58 return id(new AphrontRedirectResponse()) 58 59 ->setURI('/Q'.$question->getID());
+2 -1
src/applications/ponder/controller/PonderQuestionViewController.php
··· 33 33 if (!$question) { 34 34 return new Aphront404Response(); 35 35 } 36 - $question->attachRelated($user->getPHID()); 36 + $question->attachRelated(); 37 + $question->attachVotes($user->getPHID()); 37 38 $object_phids = array($user->getPHID(), $question->getAuthorPHID()); 38 39 39 40 $answers = $question->getAnswers();
+5 -2
src/applications/ponder/editor/PonderAnswerEditor.php
··· 34 34 35 35 public function saveAnswer() { 36 36 if (!$this->question) { 37 - throw new Exception("Must set question before saving vote"); 37 + throw new Exception("Must set question before saving answer"); 38 38 } 39 39 if (!$this->answer) { 40 - throw new Exception("Must set answer before saving vote"); 40 + throw new Exception("Must set answer before saving it"); 41 41 } 42 42 43 43 $question = $this->question; ··· 60 60 61 61 $trans->endReadLocking(); 62 62 $trans->saveTransaction(); 63 + 64 + $question->attachRelated(); 65 + PhabricatorSearchPonderIndexer::indexQuestion($question); 63 66 } 64 67 }
+51
src/applications/ponder/editor/PonderCommentEditor.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + 20 + final class PonderCommentEditor { 21 + 22 + private $question; 23 + private $comment; 24 + 25 + public function setComment(PonderComment $comment) { 26 + $this->comment = $comment; 27 + return $this; 28 + } 29 + 30 + public function setQuestion(PonderQuestion $question) { 31 + $this->question = $question; 32 + return $this; 33 + } 34 + 35 + public function save() { 36 + if (!$this->comment) { 37 + throw new Exception("Must set comment before saving it"); 38 + } 39 + if (!$this->question) { 40 + throw new Exception("Must set question before saving comment"); 41 + } 42 + 43 + $comment = $this->comment; 44 + $question = $this->question; 45 + 46 + $comment->save(); 47 + 48 + $question->attachRelated(); 49 + PhabricatorSearchPonderIndexer::indexQuestion($question); 50 + } 51 + }
+41
src/applications/ponder/editor/PonderQuestionEditor.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + 20 + final class PonderQuestionEditor { 21 + 22 + private $question; 23 + private $viewer; 24 + 25 + public function setQuestion(PonderQuestion $question) { 26 + $this->question = $question; 27 + return $this; 28 + } 29 + 30 + public function save() { 31 + if (!$this->question) { 32 + throw new Exception("Must set question before saving it"); 33 + } 34 + 35 + $question = $this->question; 36 + $question->save(); 37 + 38 + $question->attachRelated(); 39 + PhabricatorSearchPonderIndexer::indexQuestion($question); 40 + } 41 + }
+20 -7
src/applications/ponder/search/PhabricatorSearchPonderIndexer.php
··· 20 20 extends PhabricatorSearchDocumentIndexer { 21 21 22 22 public static function indexQuestion(PonderQuestion $question) { 23 + // note: we assume someone's already called attachrelated on $question 23 24 24 25 $doc = new PhabricatorSearchAbstractDocument(); 25 26 $doc->setPHID($question->getPHID()); ··· 38 39 PhabricatorPHIDConstants::PHID_TYPE_USER, 39 40 $question->getDateCreated()); 40 41 42 + $comments = $question->getComments(); 43 + foreach ($comments as $curcomment) { 44 + $doc->addField( 45 + PhabricatorSearchField::FIELD_COMMENT, 46 + $curcomment->getContent() 47 + ); 48 + } 49 + 41 50 $answers = $question->getAnswers(); 42 - $touches = array(); 43 - foreach ($answers as $comment) { 44 - if (strlen($comment->getContent())) { 51 + foreach ($answers as $curanswer) { 52 + if (strlen($curanswer->getContent())) { 53 + $doc->addField( 54 + PhabricatorSearchField::FIELD_COMMENT, 55 + $curanswer->getContent()); 56 + } 57 + 58 + $answer_comments = $curanswer->getComments(); 59 + foreach ($answer_comments as $curcomment) { 45 60 $doc->addField( 46 61 PhabricatorSearchField::FIELD_COMMENT, 47 - $comment->getContent()); 62 + $curcomment->getContent() 63 + ); 48 64 } 49 - 50 - $author = $comment->getAuthorPHID(); 51 - $touches[$author] = $comment->getDateCreated(); 52 65 } 53 66 54 67 self::reindexAbstractDocument($doc);
+22 -15
src/applications/ponder/storage/PonderQuestion.php
··· 56 56 return PhabricatorContentSource::newFromSerialized($this->contentSource); 57 57 } 58 58 59 - public function attachRelated($user_phid) { 59 + public function attachRelated() { 60 60 $this->answers = $this->loadRelatives(new PonderAnswer(), "questionID"); 61 61 $qa_phids = mpull($this->answers, 'getPHID') + array($this->getPHID()); 62 62 63 + if ($qa_phids) { 64 + $comments = id(new PonderCommentQuery()) 65 + ->withTargetPHIDs($qa_phids) 66 + ->execute(); 67 + 68 + $comments = mgroup($comments, 'getTargetPHID'); 69 + } 70 + else { 71 + $comments = array(); 72 + } 73 + 74 + $this->setComments(idx($comments, $this->getPHID(), array())); 75 + foreach ($this->answers as $answer) { 76 + $answer->setQuestion($this); 77 + $answer->setComments(idx($comments, $answer->getPHID(), array())); 78 + } 79 + } 80 + 81 + public function attachVotes($user_phid) { 82 + $qa_phids = mpull($this->answers, 'getPHID') + array($this->getPHID()); 83 + 63 84 $edges = id(new PhabricatorEdgeQuery()) 64 85 ->withSourcePHIDs(array($user_phid)) 65 86 ->withDestinationPHIDs($qa_phids) ··· 77 98 $edges[$user_phid][PhabricatorEdgeConfig::TYPE_VOTING_USER_HAS_ANSWER]; 78 99 $edges = null; 79 100 80 - if ($qa_phids) { 81 - $comments = id(new PonderCommentQuery()) 82 - ->withTargetPHIDs($qa_phids) 83 - ->execute(); 84 - 85 - $comments = mgroup($comments, 'getTargetPHID'); 86 - } 87 - else { 88 - $comments = array(); 89 - } 90 - 91 101 $this->setUserVote(idx($question_edge, $this->getPHID())); 92 - $this->setComments(idx($comments, $this->getPHID(), array())); 93 102 foreach ($this->answers as $answer) { 94 - $answer->setQuestion($this); 95 103 $answer->setUserVote(idx($answer_edges, $answer->getPHID())); 96 - $answer->setComments(idx($comments, $answer->getPHID(), array())); 97 104 } 98 105 } 99 106