2

I have a content type and some nodes. I am displaying latest 10 nodes from these content type through views block display. Is there any benefit if i add a custom SQL query to display latest 10 items. I will use the same SQL query that i got from view.

0

Another module to consider for situations where views "might need some help" is Forena (disclosure: I'm a co-maintainer of it). Here is a quote from one of its community docu pages, i.e. Reasons for considering Forena:

"Why not use views instead of forena?" ... The answer is generally something along the lines of "Most forena users love views, views is great! If you want to report against external data though, or you want to do aggregation or analytics, Forena is much more suited to address these requirements."

And since this question is about blocks also, you may want to take advantage of the Forena integration with the Bean module. Here is a quote about that module, its project page:

Think of a Bean as a method to provide new types (compared to node this would be a content type) which then provides an add content interface to create as many blocks as you require (see screenshot below). The bean content can then be placed around the site just like any other block.

You may also want to look at my answers to these somehow related, I think, questions:

1

Not really. you should stick to using Views; it will provide you more benefits. To name a couple:

  • Less custom code to maintain; it's one of the mostly heavily used modules and will be part of D8 core. There's much less worries of security holes, bugs, etc.
  • The versatility of the Views features: caching, multiple view displays, filtering, a UI to change all this, etc.

I'd say the only exception to this would be the instances where your query is going to be hit very often, in which case you'd might be able to squeeze more performance out of an optimized SQL query.

For your needs, a block of 10 latest nodes, views will do everything you need it to, not be a burden on performance, and will take much less time to complete than creating & maintaining possibly bug ridden custom code.

3
  • 1
    Thanks friend! Yeah, I appreciate it. I got downvoted because I misread the question on the 1st version of the answer where I thought it was asking a pro/con to views vs. custom queries.
    – Shawn Conn
    Jun 5 '15 at 17:30
  • 1
    If I may add, if we're worries about performance of views, server tuning and other techniques (varnish, memcache) go a long way. \
    – Rick
    Jun 5 '15 at 17:35
  • 1
    @Pierre.Vriens - I don't feel it's a separate answer. It's just a reminder to look at the big picture. I seen some developers write there own 'simpler' queries in lieu of using a more drupaly/standard method without knowing the full implications. Having a good server foundation (updated linux, tuned, with appropriate caching for your situation) may do wonders.
    – Rick
    Jun 5 '15 at 18:53

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.