Jump to content

Suggestion to improve rebuild process: go backwards


TSP

Recommended Posts

Hi,

There could be a good reason it goes from the oldest to the newest post, but if it isn't, then please consider this. 

It seems to me the rebuild goes from the first post until the last. I would want the rebuild to start with the newest post (after the upgrade) and then finish with the oldest one. 

There are two core advantages to this approach: 

  • The feeling of a slow rebuild process will be less prevalent since you'll be more likely to have 90% of the visited content within the timeframe already be rebuilt. 
  • You'll avoid rebuilding content that have been posted after the upgrade. **

** I have yet to confirm this, but it seems the rebuild process just does WHERE pid > X where X is the last postID it rebuilt. It doesn't seem to have a clearly defined stopping point, which means it'll continue as long as it received 50 items for the previous cycle. Which, depending on the page activity, would mean it would have to do more cycles than actually necessary. 

Link to comment
Share on other sites

I did wonder about this too (and the same for the 2x to 3x rebuild) as it does make logical sense to do the newest first so that members see attractive and functional posts rather than posts that are awaiting their 'fix' so to speak, as it would be bad luck for a member to complain about say a post from two years ago that was broken (as the rebuild had not got to it yet) compared to say one a few hours before the upgrade.

I've not looked into any specifics as to why its done from oldest to newest apart from its an incremental rather than decremental step.

Link to comment
Share on other sites

  • 2 weeks later...

I've decided to at least try this idea. I can't see any disadvantages, if any IPS Developers could give me a good reason you don't already do this, then please do. And if there's no reason then I would wish you to implement this sort of idea into a future update. 

Here is my changes: 

Date:   Sat Jun 27 23:33:13 2015 +0200

    RebuildPosts rebuild backwards

diff --git a/www/applications/core/extensions/core/Queue/RebuildPosts.php b/www/applications/core/extensions/core/Queue/RebuildPosts.php
index ac35446..09a638b 100644
--- a/www/applications/core/extensions/core/Queue/RebuildPosts.php
+++ b/www/applications/core/extensions/core/Queue/RebuildPosts.php
@@ -63,6 +63,8 @@ class _RebuildPosts
 		{
 			return null;
 		}
+
+		$data['offset'] = $data['count'] + 1;
 		
 		return $data;
 	}
@@ -97,7 +99,7 @@ class _RebuildPosts
 		catch( \RuntimeException $e ){}
 
 		$where	  = ( is_subclass_of( $classname, 'IPS\Content\Comment' ) ) ? ( is_array( $classname::commentWhere() ) ? array( $classname::commentWhere() ) : array() ) : array();
-		$select   = $classname::db()->select( '*', $classname::$databaseTable, array_merge( $where, array( array( $classname::$databasePrefix . $classname::$databaseColumnId . ' > ?',  $offset ) ) ), $classname::$databasePrefix . $classname::$databaseColumnId . ' ASC', array( 0, $this->rebuild ) );
+		$select   = $classname::db()->select( '*', $classname::$databaseTable, array_merge( $where, array( array( $classname::$databasePrefix . $classname::$databaseColumnId . ' < ?',  $offset ) ) ), $classname::$databasePrefix . $classname::$databaseColumnId . ' DESC', array( 0, $this->rebuild ) );
 		$iterator = new \IPS\Patterns\ActiveRecordIterator( $select, $classname );
 		$last     = NULL;
 		
@@ -107,10 +109,10 @@ class _RebuildPosts
 
 			/* If the ID is greater than the max we started with, don't rebuild - we're done because this post and any newer
 				will have been posted under 4.0 already */
-			if( $item->$idColumn >= $data['count'] )
+			/*if( $item->$idColumn >= $data['count'] )
 			{
 				return NULL;
-			}
+			}*/
 
 			$member     = \IPS\Member::load( $item->mapped('author') );
 			$extensions = \IPS\Application::load( $classname::$application )->extensions( 'core', 'EditorLocations' );
@@ -212,6 +214,6 @@ class _RebuildPosts
 			throw new \OutOfRangeException;
 		}
 		
-		return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('rebuilding_stuff', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( $class::$title . '_pl', FALSE, array( 'strtolower' => TRUE ) ) ) ) ), 'complete' => $data['count'] ? ( round( 100 / $data['count'] * $offset, 2 ) ) : 100 );
+		return array( 'text' => \IPS\Member::loggedIn()->language()->addToStack('rebuilding_stuff', FALSE, array( 'sprintf' => array( \IPS\Member::loggedIn()->language()->addToStack( $class::$title . '_pl', FALSE, array( 'strtolower' => TRUE ) ) ) ) ), 'complete' => $data['count'] ? ( round( 100 - (100 / $data['count'] * $offset), 2 ) ) : 100 );
 	}	
-}
\ No newline at end of file
+}
diff --git a/www/system/Task/Task.php b/www/system/Task/Task.php
index 7b84ffc..76d49fe 100644
--- a/www/system/Task/Task.php
+++ b/www/system/Task/Task.php
@@ -49,10 +49,18 @@ class _Task extends \IPS\Patterns\ActiveRecord
 			throw new \InvalidArgumentException;
 		}
 		
+		$offset = 0;
+
 		if ( method_exists( $extensions[ $key ], 'preQueueData' ) )
 		{
 			$class = new $extensions[ $key ];
 			$data = $class->preQueueData( $data );
+
+			if( isset( $data['offset'] ) and $data['offset'] != 0 )
+			{
+				$offset = $data['offset'];	
+			}
+
 			if ( $data === NULL )
 			{
 				return;
@@ -91,7 +99,8 @@ class _Task extends \IPS\Patterns\ActiveRecord
 			'date'		=> time(),
 			'app'		=> $app,
 			'key'		=> $key,
-			'priority'	=> $priority
+			'priority'	=> $priority,
+			'offset'    => $offset
 		) );
 		
 		\IPS\DB::i()->update( 'core_tasks', array( 'enabled' => 1 ), array( '`key`=?', 'queue' ) );

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...