EBernhardson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/106449
Change subject: Track the root of a post tree explicitly
......................................................................
Track the root of a post tree explicitly
Querying the TreeRepository from the TopicHistoryIndex is open
to slave-lag issues, the just-added post may not actually
be available in the slave yet.
Anything we are saving we already know the root for, we just didn't
have the information available in the TopicHistoryIndex. This patch
adds another field, rootPost, which is set when loading the posts. That
allows the information to make it into the TopicHistoryIndex
and remove the need for the TreeRepository there.
Change-Id: I23854ac0e36d8b892eba0d1202c1fd81dc05bd6e
---
M container.php
M includes/Block/Topic.php
M includes/Data/RevisionStorage.php
M includes/Data/RootPostLoader.php
M includes/Model/PostRevision.php
5 files changed, 41 insertions(+), 9 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/49/106449/1
diff --git a/container.php b/container.php
index 68c8b54..19fbae5 100644
--- a/container.php
+++ b/container.php
@@ -311,7 +311,7 @@
// topic history -- to keep a history by topic we have to know
what topic every post
// belongs to, not just its parent. TopicHistoryIndex is a
slight tweak to TopKIndex
// using TreeRepository for extra information and stuffing it
into topic_root while indexing
- new TopicHistoryIndex( $cache, $storage, $c['repository.tree'],
'flow_revision:topic',
+ new TopicHistoryIndex( $cache, $storage, 'flow_revision:topic',
array( 'topic_root_id' ),
array(
'limit' => 500,
diff --git a/includes/Block/Topic.php b/includes/Block/Topic.php
index 01a3ec1..19c9b43 100644
--- a/includes/Block/Topic.php
+++ b/includes/Block/Topic.php
@@ -869,6 +869,7 @@
// looking for loadRootPost
$this->topicTitle->setChildren( array() );
$this->topicTitle->setDepth( 0 );
+ $this->topicTitle->setRootPost( $this->topicTitle );
if ( !$this->permissions->isAllowed( $this->topicTitle,
'view' ) ) {
$this->topicTitle = null;
@@ -931,6 +932,7 @@
// using the path to the root post, we can know the
post's depth
$rootPath = $this->rootLoader->treeRepo->findRootPath(
$postId );
$post->setDepth( count( $rootPath ) - 1 );
+ $post->setRootPost( $found['root'] );
}
if ( $this->permissions->isAllowed( $topicTitle, 'view' )
@@ -974,13 +976,16 @@
if ( !$found ) {
throw new InvalidInputException( 'Should have found
revisions', 'missing-revision' );
}
- // Because storage returns a new object for every query
- // We need to find $post in the array and replace it
$revId = $post->getRevisionId();
+ $rootPost = $post->getRootPost();
foreach ( $found as $idx => $revision ) {
if ( $revId->equals( $revision->getRevisionId() ) ) {
+ // Because storage returns a new object for
every query
+ // We need to find $post in the array and
replace it
$found[$idx] = $post;
- break;
+ } else {
+ // Root post needs to propogate from $post to
found revisions
+ $revision->setRootPost( $rootPost );
}
}
return $found;
diff --git a/includes/Data/RevisionStorage.php
b/includes/Data/RevisionStorage.php
index 7fd0bd7..900bf89 100644
--- a/includes/Data/RevisionStorage.php
+++ b/includes/Data/RevisionStorage.php
@@ -489,26 +489,25 @@
protected $treeRepository;
- public function __construct( BufferedCache $cache, PostRevisionStorage
$storage, TreeRepository $treeRepo, $prefix, array $indexed, array $options =
array() ) {
+ public function __construct( BufferedCache $cache, PostRevisionStorage
$storage, $prefix, array $indexed, array $options = array() ) {
if ( $indexed !== array( 'topic_root_id' ) ) {
throw new \MWException( __CLASS__ . ' is hardcoded to
only index topic_root_id: ' . print_r( $indexed, true ) );
}
parent::__construct( $cache, $storage, $prefix, $indexed,
$options );
- $this->treeRepository = $treeRepo;
}
public function onAfterInsert( $object, array $new ) {
- $new['topic_root_id'] = $this->treeRepository->findRoot(
UUID::create( $new['tree_rev_descendant_id'] ) )->getBinary();
+ $new['topic_root_id'] =
$object->getRootPost()->getPostId()->getBinary();
parent::onAfterInsert( $object, $new );
}
public function onAfterUpdate( $object, array $old, array $new ) {
- $old['topic_root_id'] = $new['topic_root_id'] =
$this->treeRepository->findRoot( UUID::create( $old['tree_rev_descendant_id'] )
)->getBinary();
+ $old['topic_root_id'] = $new['topic_root_id'] =
$object->getRootPost()->getPostId()->getBinary();
parent::onAfterUpdate( $object, $old, $new );
}
public function onAfterRemove( $object, array $old ) {
- $old['topic_root_id'] = $this->treeRepository->findRoot(
UUID::create( $old['tree_rev_descendant_id'] ) );
+ $old['topic_root_id'] =
$object->getRootPost()->getPostId()->getBinary();
parent::onAfterRemove( $object, $old );
}
diff --git a/includes/Data/RootPostLoader.php b/includes/Data/RootPostLoader.php
index caaa64d..8fcf1b6 100644
--- a/includes/Data/RootPostLoader.php
+++ b/includes/Data/RootPostLoader.php
@@ -141,6 +141,10 @@
foreach ( $topicIds as $id ) {
$roots[$id->getHex()] = $posts[$id->getHex()];
}
+ // Attach every post in the tree to its root
+ foreach ( $roots as $hex => $post ) {
+ $post->setRootPost( $post );
+ }
return $roots;
}
diff --git a/includes/Model/PostRevision.php b/includes/Model/PostRevision.php
index e4f4dd6..401cae9 100644
--- a/includes/Model/PostRevision.php
+++ b/includes/Model/PostRevision.php
@@ -20,6 +20,7 @@
// Data that is loaded externally and set
protected $children;
protected $depth;
+ protected $rootPost;
/**
* Variables callback functions & their results will be saved to.
@@ -47,6 +48,7 @@
// A newly created post has no children and a depth of 0
$obj->setChildren( array() );
$obj->setDepth( 0 );
+ $obj->rootPost = $obj;
return $obj;
}
@@ -95,6 +97,7 @@
$reply->changeType = $changeType;
$reply->setChildren( array() );
$reply->setDepth( $this->getDepth() + 1 );
+ $reply->rootPost = $this->rootPost;
return $reply;
}
@@ -132,6 +135,10 @@
public function setChildren( array $children ) {
$this->children = $children;
+ if ( $this->rootPost ) {
+ // propogate root post into children
+ $this->setRootPost( $this->rootPost );
+ }
}
public function getChildren() {
@@ -152,6 +159,23 @@
return $this->depth;
}
+ public function setRootPost( PostRevision $root ) {
+ $this->rootPost = $root;
+ if ( $this->children ) {
+ // propogate root post into children
+ foreach ( $this->children as $child ) {
+ $child->setRootPost( $root );
+ }
+ }
+ }
+
+ public function getRootPost() {
+ if ( $this->rootPost === null ) {
+ throw new DataModelException( 'Depth not loaded for
post: ' . $this->postId->getHex(), 'process-data' );
+ }
+ return $this->rootPost;
+ }
+
/**
* Get the amount of posts in this topic.
*
--
To view, visit https://gerrit.wikimedia.org/r/106449
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I23854ac0e36d8b892eba0d1202c1fd81dc05bd6e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits