Thanks for you response. I split it up a bit. I don't know how the speed is since I only have a few hundred posts to try it on (on these posts it's instant though). This is the way I do it now. Any recommendations?
PHP Code:
// Set the board in maintenance mode
mysql_query( "UPDATE options SET maintenance='yes'" ) or error( mysql_errno(), __LINE__, mysql_error() );
// Select the thread ID's (parentid=0)
$result = mysql_query( 'SELECT id FROM messages WHERE parentid=0 and lastpost < UNIX_TIMESTAMP()-('.intval( $pruneseconds ).')' ) or error( mysql_errno(), __LINE__, mysql_error() );
$numthreads = mysql_num_rows( $result );
$threadcount = 0;
if( $numthreads > 0 )
{
do
{
$threads = NULL;
for( $tempcount = 0; $threadcount < $numthreads; $threadcount++ )
{
if( $tempcount == 8 ) // We only do 8 threads at a time. Otherwise the query would be "too long".
break;
$threads[] = mysql_result( $result, $threadcount );
$tempcount++;
}
if( $threads == NULL ) // We're done
break;
$threadstring = implode( ', ', $threads );
mysql_query( 'DELETE FROM messages WHERE id IN( '.$threadstring.' ) OR parentid IN( '.$threadstring.' )' ) or error( mysql_errno(), __LINE__, mysql_error() );
} while( mysql_affected_rows() > 0 );
mysql_query( 'OPTIMIZE TABLE messages' ) or error( mysql_errno(), __LINE__, mysql_error() );
}
else
echo 'nothing to prune';
mysql_query( "UPDATE options SET maintenance='no'" ) or error( mysql_errno(), __LINE__, mysql_error() );
Bookmarks