3

I have written a module that writes views programmatically, and my mymodule.views_default.inc file is enormous. Currently there are 150 individual views, and 780 will be the target.

But, even with the test group of 150 several things are happening.

1) when enabling the module via drush, php memory usage goes through the roof. It climbs into the gigs (TOP command), but it finally loads.

2) but, when I then try to view the site I get WSOD, and the top command shows apache2 climbs into the gigs for memory usage until the Apache process actually crashes. Of course there is not enough memory to load it, and it's of course unrealistic to put php memory limit in the gigs.

What's going on here? How is the code in mymodule.views_default.inc actually handled once it's loaded? Where is it being loaded to? Is it loaded into memory for each Apache process? If I can actually get it loaded will my Apache process footprints actually shrink back down to something normal?

Can this file be divided up into individual files, and would this even help? Is it better to someway put them into the database instead of using the file at all?

In other words, how can I get almost 1000 views loaded and continue doing business as usual?

note, if you are curious, this is a census data project. I don't want to use filters or arguments as each set of data needs to to have its own individual page URL and other criteria unique to that data set.

  • 1
    Before writing an answer to this, I would like to know what on earth you are doing with 780 Views. Having individual urls is not a reason to avoid arguments. The reason to have so many views will likely affect what my answer could look like. – Letharion Aug 16 '13 at 11:14
  • 1
    Seems strange to set yourself a target, the sensible target with views is to use as few as is physically possible! As @Letharion alludes to, if you're planning to have that many, the design of your app is off somewhere. There's nothing you can do with 780 Views you couldn't do with a handful of Views with appropriate relationships/filters, and maybe a few custom handlers. As an actual answer to how can I get almost 1000 views loaded and continue doing business as usual?: hardware, hardware, hardware - get better servers :) – Clive Aug 16 '13 at 11:34
2

I'm not 100% sure if it'd help performance-wise, but it is possible to separate the Views into different files. In your case, this is probably useful anyway as that's a LOT of Views.

If you create a folder in your module called "views" (or whatever you want), then you can just add the following to your implementation of hook_views_default_views.

function MYMODULE_views_default_views() {
  $files = file_scan_directory(drupal_get_path('module', 'MYMODULE'). '/views', '/.view/');
  foreach ($files as $filepath => $file) {
    require $filepath;
    if (isset($view)) {
      $views[$view->name] = $view;
    }
  }
  return $views;
}

DISCLAIMER/CREDIT:

This code was taken from this blog post, and this comment, so make sure you pop over there and say thank you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.