Skip to content

Commit

Permalink
Fix EZP-23681: Delayed indexing of subtree on move
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickroger committed Dec 2, 2014
1 parent 79ed304 commit 9a15f89
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 8 deletions.
57 changes: 55 additions & 2 deletions cronjobs/indexcontent.php
Expand Up @@ -29,7 +29,7 @@
while( true )
{
$entries = $db->arrayQuery(
"SELECT param FROM ezpending_actions WHERE action = 'index_object' GROUP BY param ORDER BY min(created)",
"SELECT param, action FROM ezpending_actions WHERE action = 'index_object' OR action = 'index_moved_node' GROUP BY param ORDER BY min(created)",
array( 'limit' => $limit, 'offset' => $offset )
);

Expand All @@ -38,6 +38,7 @@
foreach ( $entries as $entry )
{
$objectID = (int)$entry['param'];
$action = $entry['action'];

$cli->output( "\tIndexing object ID #$objectID" );
$db->begin();
Expand All @@ -49,12 +50,64 @@
{
$searchEngine->removeObject( $object, false );
}

$removeFromPendingActions = $searchEngine->addObject( $object, false );

// When moving content (and only, because of performances), reindex the subtree
if ( $action == 'index_moved_node' )
{
$nodeId = $object->attribute( 'main_node_id' );
$node = eZContentObjectTreeNode::fetch( $nodeId );

if ( !( $node instanceof eZContentObjectTreeNode ) )
{
$cli->error( "An error occured while trying fetching node $nodeId" );

This comment has been minimized.

Copy link
@guillaumelecerf

guillaumelecerf Dec 2, 2014

Contributor

continue ?

This comment has been minimized.

Copy link
@yannickroger

yannickroger Dec 2, 2014

Author Contributor

You should open a PR with your last remarks on commits :)
913dc38#commitcomment-8412190
5c42732#commitcomment-8577109

This comment has been minimized.

Copy link
@guillaumelecerf

guillaumelecerf Dec 3, 2014

Contributor

See #1122 for this error

}

$offset = 0;
$limit = 50;

$params = array( 'Limitation' => array(), 'MainNodeOnly' => true );

$subtreeCount = $node->subTreeCount( $params );

while ( $offset < $subtreeCount )
{
$subTree = $node->subTree(
array_merge(
$params,
array( 'Offset' => $offset, 'Limit' => $limit, 'SortBy' => array() )
)
);

if ( !empty( $subTree ) )
{
foreach ( $subTree as $innerNode )
{
/** @var $innerNode eZContentObjectTreeNode */
$childObject = $innerNode->attribute( 'object' );
if ( !$childObject )
{
continue;
}

$searchEngine->addObject( $childObject, false );
}
}

$offset += $limit;

if ( $offset >= $subtreeCount )
{
break;
}
}
}
}

if ( $removeFromPendingActions )
{
$db->query( "DELETE FROM ezpending_actions WHERE action = 'index_object' AND param = '$objectID'" );
$db->query( "DELETE FROM ezpending_actions WHERE action = '$action' AND param = '$objectID'" );
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions kernel/classes/ezcontentobjecttreenodeoperations.php
Expand Up @@ -109,10 +109,10 @@ static function move( $nodeID, $newParentNodeID )
$nodeAssignment->setAttribute( 'op_code', eZNodeAssignment::OP_CODE_MOVE );
$nodeAssignment->store();

// update search index
// update search index specifying we are doing a move operation
$nodeIDList = array( $nodeID );
eZSearch::removeNodeAssignment( $node->attribute( 'main_node_id' ), $newNode->attribute( 'main_node_id' ), $object->attribute( 'id' ), $nodeIDList );
eZSearch::addNodeAssignment( $newNode->attribute( 'main_node_id' ), $object->attribute( 'id' ), $nodeIDList );
eZSearch::addNodeAssignment( $newNode->attribute( 'main_node_id' ), $object->attribute( 'id' ), $nodeIDList, true );
}

$result = true;
Expand Down
5 changes: 3 additions & 2 deletions kernel/classes/ezsearch.php
Expand Up @@ -563,15 +563,16 @@ public static function updateNodeVisibility( $nodeID, $action )
* @param int $mainNodeID
* @param int $objectID
* @param array $nodeAssignmentIDList
* @param bool $isMoved true if node is being moved
* @return false|mixed False in case method is undefined, otherwise return the result of the search engine call
*/
public static function addNodeAssignment( $mainNodeID, $objectID, $nodeAssignmentIDList )
public static function addNodeAssignment( $mainNodeID, $objectID, $nodeAssignmentIDList, $isMoved = false )
{
$searchEngine = eZSearch::getEngine();

if ( $searchEngine instanceof ezpSearchEngine && method_exists( $searchEngine, 'addNodeAssignment' ) )
{
return $searchEngine->addNodeAssignment( $mainNodeID, $objectID, $nodeAssignmentIDList );
return $searchEngine->addNodeAssignment( $mainNodeID, $objectID, $nodeAssignmentIDList, $isMoved );
}

return false;
Expand Down
8 changes: 6 additions & 2 deletions kernel/content/ezcontentoperationcollection.php
Expand Up @@ -565,8 +565,10 @@ static public function resetNodeassignmentOpcodes( $objectID, $versionNum )
* the calls within a db transaction; thus within db->begin and db->commit.
*
* @param int $objectID Id of the object.
* @param int $version Operation collection passes this default param. Not used in the method
* @param bool $isMoved true if node is being moved
*/
static public function registerSearchObject( $objectID )
static public function registerSearchObject( $objectID, $version = null, $isMoved = false )
{
$objectID = (int)$objectID;
eZDebug::createAccumulatorGroup( 'search_total', 'Search Total' );
Expand All @@ -591,7 +593,9 @@ static public function registerSearchObject( $objectID )

if ( $insertPendingAction )
{
eZDB::instance()->query( "INSERT INTO ezpending_actions( action, param ) VALUES ( 'index_object', '$objectID' )" );
$action = $isMoved ? 'index_moved_node' : 'index_object';

eZDB::instance()->query( "INSERT INTO ezpending_actions( action, param ) VALUES ( '$action', '$objectID' )" );
return;
}

Expand Down
Expand Up @@ -53,6 +53,7 @@ public function tearDown()
$this->folder->remove();
$this->article->remove();
eZPendingActions::removeByAction( 'index_object' );
eZPendingActions::removeByAction( 'index_moved_node' );
$this->nodeIds = array();
$this->objectIds = array();

Expand Down

1 comment on commit 9a15f89

@xrow
Copy link
Contributor

@xrow xrow commented on 9a15f89 Dec 30, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about content hide operations are they safe?

Please sign in to comment.