R
ragtek
Guest
i'm not sure if i misunderstood you, or if your way is also not optimalAll you can do is select more than you need and hope that when you filter them, you have n remaining. Any more than that, you can chop off.
(This is the principle behind pretty much every search engine that has to manage diverse data)

the current code (with your suggestion) is=> https://github.com/ragtek/xf-addons/blob/master/Latest.php
method getLatestPostsNew
this method is very time consuming on big boards
the limit, which i had in the past, helps here really
PHP:
$nodeModel = XenForo_Model::create('XenForo_Model_Node');
$viewableNodeList = $nodeModel->getViewableNodeList(); // check if this returns pages too, if yes, we need an other way
$nodes = array_keys($viewableNodeList);
$where = implode(',', $nodes);