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

Add a ref cache and index construction to Diviner

Summary: Cache refs in a single large index; rebuild the main index from them.

Test Plan: {F32334}

Reviewers: btrahan, vrana, chad

Reviewed By: chad

CC: aran

Maniphest Tasks: T988

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

+157 -5
+7 -1
src/applications/diviner/atom/DivinerAtom.php
··· 284 284 } 285 285 286 286 public function getRef() { 287 + $group = null; 288 + if ($this->docblockMeta) { 289 + $group = $this->getDocblockMetaValue('group'); 290 + } 291 + 287 292 return id(new DivinerAtomRef()) 288 293 ->setBook($this->getBook()) 289 294 ->setContext($this->getContext()) 290 295 ->setType($this->getType()) 291 - ->setName($this->getName()); 296 + ->setName($this->getName()) 297 + ->setGroup($group); 292 298 } 293 299 294 300 public static function newFromDictionary(array $dictionary) {
+53
src/applications/diviner/atom/DivinerAtomRef.php
··· 6 6 private $context; 7 7 private $type; 8 8 private $name; 9 + private $group; 10 + private $summary; 11 + private $index; 12 + 13 + public function getSortKey() { 14 + return implode( 15 + "\0", 16 + array( 17 + $this->getName(), 18 + $this->getType(), 19 + $this->getContext(), 20 + $this->getBook(), 21 + $this->getIndex(), 22 + )); 23 + } 24 + 25 + public function setIndex($index) { 26 + $this->index = $index; 27 + return $this; 28 + } 29 + 30 + public function getIndex() { 31 + return $this->index; 32 + } 33 + 34 + public function setSummary($summary) { 35 + $this->summary = $summary; 36 + return $this; 37 + } 38 + 39 + public function getSummary() { 40 + return $this->summary; 41 + } 9 42 10 43 public function setName($name) { 11 44 $normal_name = self::normalizeString($name); ··· 53 86 return $this->book; 54 87 } 55 88 89 + public function setGroup($group) { 90 + $this->group = $group; 91 + return $this; 92 + } 93 + 94 + public function getGroup() { 95 + return $this->group; 96 + } 97 + 56 98 public function toDictionary() { 57 99 return array( 58 100 'book' => $this->getBook(), 59 101 'context' => $this->getContext(), 60 102 'type' => $this->getType(), 61 103 'name' => $this->getName(), 104 + 'group' => $this->getGroup(), 105 + 'index' => $this->getIndex(), 106 + 'summary' => $this->getSummary(), 62 107 ); 63 108 } 64 109 65 110 public function toHash() { 66 111 $dict = $this->toDictionary(); 112 + 113 + unset($dict['group']); 114 + unset($dict['index']); 115 + unset($dict['summary']); 116 + 67 117 ksort($dict); 68 118 return md5(serialize($dict)).'S'; 69 119 } ··· 74 124 $obj->context = idx($dict, 'context'); 75 125 $obj->type = idx($dict, 'type'); 76 126 $obj->name = idx($dict, 'name'); 127 + $obj->group = idx($dict, 'group'); 128 + $obj->index = idx($dict, 'index'); 129 + $obj->summary = idx($dict, 'summary'); 77 130 return $obj; 78 131 } 79 132
+28
src/applications/diviner/cache/DivinerPublishCache.php
··· 3 3 final class DivinerPublishCache extends DivinerDiskCache { 4 4 5 5 private $pathMap; 6 + private $index; 6 7 7 8 public function __construct($cache_directory) { 8 9 return parent::__construct($cache_directory, 'diviner-publish-cache'); ··· 41 42 return $this; 42 43 } 43 44 45 + 46 + /* -( Index )-------------------------------------------------------------- */ 47 + 48 + public function getIndex() { 49 + if ($this->index === null) { 50 + $this->index = $this->getCache()->getKey('index', array()); 51 + } 52 + return $this->index; 53 + } 54 + 55 + public function writeIndex() { 56 + $this->getCache()->setKey('index', $this->getIndex()); 57 + } 58 + 59 + public function deleteAtomFromIndex($hash) { 60 + $index = $this->getIndex(); 61 + unset($index[$hash]); 62 + $this->index = $index; 63 + return $this; 64 + } 65 + 66 + public function addAtomToIndex($hash, array $data) { 67 + $index = $this->getIndex(); 68 + $index[$hash] = $data; 69 + $this->index = $index; 70 + return $this; 71 + } 44 72 45 73 }
+43 -4
src/applications/diviner/publisher/DivinerStaticPublisher.php
··· 53 53 54 54 $cache->removeAtomPathsFromCache($hash); 55 55 $cache->deleteRenderCache($hash); 56 + $cache->deleteAtomFromIndex($hash); 56 57 } 57 - 58 - $cache->writePathMap(); 59 58 } 60 59 61 60 protected function createDocumentsByHash(array $hashes) { 62 61 $indexes = array(); 62 + 63 + $cache = $this->getPublishCache(); 63 64 64 65 foreach ($hashes as $hash) { 65 66 $atom = $this->getAtomFromGraphHash($hash); ··· 76 77 $indexes[$index] = $atom; 77 78 $paths[] = $index; 78 79 } 80 + 81 + $this->addAtomToIndex($hash, $atom); 79 82 } 80 83 81 - $this->getPublishCache()->addAtomPathsToCache($hash, $paths); 84 + $cache->addAtomPathsToCache($hash, $paths); 85 + } 86 + 87 + foreach ($indexes as $index => $atoms) { 88 + // TODO: Publish disambiguation pages. 89 + } 90 + 91 + $this->publishIndex(); 92 + 93 + $cache->writePathMap(); 94 + $cache->writeIndex(); 95 + } 96 + 97 + private function publishIndex() { 98 + $index = $this->getPublishCache()->getIndex(); 99 + $refs = array(); 100 + foreach ($index as $hash => $dictionary) { 101 + $refs[$hash] = DivinerAtomRef::newFromDictionary($dictionary); 82 102 } 83 103 84 - $this->getPublishCache()->writePathMap(); 104 + $content = $this->getRenderer()->renderAtomIndex($refs); 105 + 106 + $path = implode( 107 + DIRECTORY_SEPARATOR, 108 + array( 109 + $this->getConfig('root'), 110 + 'docs', 111 + $this->getConfig('name'), 112 + 'index.html', 113 + )); 114 + 115 + Filesystem::writeFile($path, $content); 116 + } 117 + 118 + private function addAtomToIndex($hash, DivinerAtom $atom) { 119 + $ref = $atom->getRef(); 120 + $ref->setIndex($this->getAtomSimilarIndex($atom)); 121 + $ref->setSummary($this->getRenderer()->renderAtomSummary($atom)); 122 + 123 + $this->getPublishCache()->addAtomToIndex($hash, $ref->toDictionary()); 85 124 } 86 125 87 126 private function writeDocument(DivinerAtom $atom, $content) {
+24
src/applications/diviner/renderer/DivinerDefaultRenderer.php
··· 6 6 return "ATOM: ".$atom->getType()." ".$atom->getName()."!"; 7 7 } 8 8 9 + public function renderAtomSummary(DivinerAtom $atom) { 10 + return "A lovely atom named ".$atom->getName(); 11 + } 12 + 13 + public function renderAtomIndex(array $refs) { 14 + $refs = msort($refs, 'getSortKey'); 15 + 16 + $groups = mgroup($refs, 'getGroup'); 17 + 18 + $out = array(); 19 + foreach ($groups as $group_key => $refs) { 20 + $out[] = '<h1>'.$group_key.'</h1>'; 21 + $out[] = '<ul>'; 22 + foreach ($refs as $ref) { 23 + $out[] = '<li>'.$ref->getName().' - '.$ref->getSummary().'</li>'; 24 + } 25 + $out[] = '</ul>'; 26 + } 27 + $out = implode("\n", $out); 28 + 29 + return $out; 30 + } 31 + 32 + 9 33 }
+2
src/applications/diviner/renderer/DivinerRenderer.php
··· 3 3 abstract class DivinerRenderer { 4 4 5 5 abstract public function renderAtom(DivinerAtom $atom); 6 + abstract public function renderAtomSummary(DivinerAtom $atom); 7 + abstract public function renderAtomIndex(array $refs); 6 8 7 9 }