I have the latest Drupal 7 running on a Centos OS.

I have a content type named publications which is composed of lets say around 20 fields (i.e. publication title, name, doi, authors, keywords, date, chapter, etc etc.).

I have Staff content type that references Publications using Entity References. One of our staff has around 700 publications (700 references from Staff node to publication nodes).

I have a view of type page with following features/conditions:

  1. Contextual filter that accepts username of the staff as arg (filters only those publications referenced by that staff whose username is supplied as argument)
  2. Filter on Staff and Publication content types
  3. Relationship (A bridge to the Content entity that is referencing Content via field_staff_selected_publication)
  4. Show output as Fields (I construct a publication entry that should look as follow using the fields of publication content type)

    Role of aberrant HLA-DR expression and antigen presentation in induction of endocrine autoimmunity. Bottazzo GF, Pujol-Borrell R, Hanafusa T, Feldmann M . Lancet 1983; 2: 1115-1119

The execution time is directly dependent upon the number of publication nodes, one of our staff has around 600 publications and I have get the following execution times for him:

Query build time    4.35 ms
Query execute time  60.24 ms
View render time     6226.73 ms

Executing the view for a staff that has 170 publications, I get the following time

Query build time    1.8 ms
Query execute time  18.99 ms
View render time    2107.41 ms

I have the following code to attach the view in the node template file (node--staff.tpl.php)

<div id="selected-publications" class="tab-pane fade in active key-publications">
      <?php print views_embed_view('selected_publications', 'page',$node->field_staff_username['und'][0]['value']); ?>
    <div id="all-publications" class="tab-pane fade all-publications">
      <?php print views_embed_view('all_publications', 'page',$node->field_staff_username['und'][0]['value']); ?>

Opening the staff profile with huge number of publication causes a delay in page showing up because, obviously Drupal executes the view and gets back the result and render it. I do know that Views cache or Boost module might help me here to cache the result of the view rather then execute it every time the page is visited but, I am looking for a more efficient approach.

I would like the node--staff.tpl.php page to execute the views_embed_view only when the document loading is done (this would render everything else in the page but, the publication parts will get rendered afterwards).


I would like the views_embed_view to be executed asyncronously (in the background) via ajax or similar solution. The would avoid the page from waiting and while the user is looking at the rest of the page, the publications are rendered in the background.

At the moment, opening the profile page of one of our scientists with 600 publication take around 10 seconds, I believe 8 second of that is because of rendering the view, If I be able to do this 8 second in the background, that would be AMAZING.

Thank you in advance for you help/advise.

  • I do know that embedding a view to a .tpl.php file is a bad idea. I am a big fun of low coupling but, this is how the situation demands. – Raf Sep 12 '14 at 15:34
  • 3
    Sounds pretty easy, just make a page callback that prints the embedded view and use jQuery to request it via ajax and show it in the page – Clive Sep 12 '14 at 15:42
  • @Clive: I have the similar problem, Could it be possible to give more details. Thanks Raf Any luck ? – Yama Sep 13 '14 at 20:20

Your Answer

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

Browse other questions tagged or ask your own question.