Error with large number of items

Created on 26 June 2017, over 7 years ago
Updated 7 June 2023, over 1 year ago

We have ~1200 news articles, and it seems to cause some error when the View filter allows all the 1000+ articles.

I'm sorry this is going to be a crappy bug, but I can't figure out were the code is erroring. It must be some kind of out-of-memory error, because nothing is appearing in the logs?

It only seems to happen when placing the pager block on the article pages. The pager renders in the "Edit View" preview area just fine (it says "1 of 1270", etc). But when I place the block on the article page, I get a "white page of death".

I am not able to get any errors or stack traces, in any of the logs (either output to the screen or in apache, php-fpm, the Drupal DB log, etc, with all error reporting turned on...). (No "performance suggestions" appear, either).

I have even stepped through the extension code, and commented out parts (like the counter), and it doesn't seem like any code in this module itself is erroring. I can't figure it out.

If I set the pager to LIMIT 10 (ish), or add filters to reduce the number of items, the pager renders as expected.

Sorry for the poor bug, but I thought I would file it in case anyone can track down what loop or something is choking on 1000+ items. Thanks.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States thaddeusmt

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡¬πŸ‡§United Kingdom sp3boy

    I am adopting the patch from #8 as a much-needed solution for the rendering limit and general performance issues. I agree with the suggested refinements but for now this makes it possible for me to provide the site functionality.

  • Status changed to Needs work 8 days ago
  • πŸ‡¬πŸ‡§United Kingdom joachim

    There seem to be some unrelated changes in this patch.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    Instead of hacking things out in prerender -- when the entities have been loaded already, which is going to be one of the big causes of poor performance -- I wonder whether we can restrict the query.

    The answer here using LAG and LEAD looks promising -- https://stackoverflow.com/questions/32036864/select-a-row-and-the-rows-e...

  • πŸ‡¬πŸ‡§United Kingdom joachim

    I can get this to work by hacking in the Views SQL plugin and wrapping the returned query:

        $query->addExpression('LAG(node_field_data.nid) over ()', 'lag_nid');
        $query->addExpression('LEAD(node_field_data.nid) OVER ()', 'lead_nid');
    
        $outer = $this->getConnection()
          ->select($query, 'inner');
        $outer->fields('inner', []);
        // $outer->condition('lag_nid', NID, '=');
        // OR
        // $outer->condition('lead_nid', NID, '=');
    
        return $outer;
    

    This POC shows that it's possible to wrap the query in another, and use the lag/lead expressions.

    However, to use this we need:

    - to switch the query plugin, and Views only allows base tables to specify a different query plugin. We really don't want to have to redefine EVERY table (and expect users to know to use a different base table). What we could do is override getPlugin() in DisplayPluginBase, which would mean we need a custom display. But having an 'Entity Pager' display type makes sense.
    - we need the current entity ID to pass to the query as a condition. We could do the same technique with the route match, though doing it that deep in Views feels a bit wrong -- would be nicer to have it as a default argument plugin.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    > to switch the query plugin

    I think this is actually possible in the pager plugin after all.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    Done!
    I've actually added two techniques for optimisation -

    - pre-query, using LAG() and LEAD() as described above. This will scale best to very large result sets, but the query alteration might cause problems with complex queries (such as using GROUP BY, maybe -- I've not experimented)
    - post-query, removing rows from the result that are not relevant. This is similar to the patches above, but crucially runs *before* the SQL Views query plugin loads the entities for each row. It will still not scale as well, as for very large result sets, the whole initial result is still loaded into PHP -- but it's probably fine up to several thousand rows.

    Please review!

Production build 0.71.5 2024