Alter a view to show the first N results
You need to alter the pager, see ViewExecutable:initPager(), so right now only this code works (seems confusing ..):

function mycustommodule_views_query_alter(\Drupal\views\ViewExecutable $view, \Drupal\views\Plugin\views\query\QueryPluginBase $query){
    if($view-&gt;id() == 'mycustomview'){
        $view-&gt;setOffset(5);
        $view-&gt;getPager()-&gt;setItemsPerPage(7);
    }
}



  Is that code touched only the first time ? (After running drush cr)


If so - move the method in a file called mycustommodule.views_execution.inc. It won't work on every request inside mycustommodule.module file. see here!


  Also make sure Disable SQL rewriting is not set in the view used !


For more information see the issue I addressed regarding this on d.o.