Skip Navigation

[Resolved] Post relationship overhead on post where there is no relationship

This support ticket is created 5 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by Luo Yang 5 years, 10 months ago.

Assisted by: Luo Yang.

Author
Posts
#1190322

Hi,

This is a pretty basic question, just wanted to confirm that my understanding is correct.

I have 2 types of post on my site - Books & Videos.

Some books may have a video that is related to them, but the vast majority will not. If aim to create a many-to-many post relationship between the two post types, and a view to display content of the related post in the post being displayed.

I wanted to understand what happens when there is no relationship in a given post. Does the view still get fired and consume server resources even when there is no relationship, or does the view only get fired when there is a relationship to display.

#1190337

Hello,

Yes, the view will be fired even there isn't any result.

But there is a built-in cache within Views plugin, by default Views will use cache to display the results, so it will not consume a lots of your server resources, see our document:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-view
cached (opt):
off
Turns off the caching system for the View.

And here is a document about "How to Use Views Custom Search on Large Sites":
https://toolset.com/documentation/user-guides/front-page-filters/how-to-use-views-parametric-search-on-large-sites/

For your reference.

#1190354

As per my understanding, a view generated via a post-relationship will not get cached due to the way the views caching works.

I had asked this specific question on whether post relationships views can get cached in a previous support thread: https://toolset.com/documentation/user-guides/front-page-filters/how-to-use-views-parametric-search-on-large-sites/ and providing a snippet of the answer below

"these criteria are important:
- The View shortcode has any attribute other than name, id or target_id....
- The View is nested or has a filter or an option that depends on the current page, current user, or current archive data.
- Things that also change the content or the status of posts, terms, or users will invalidate cache automatically.
This View of the author bio must either include a shortcode attribute which sets the context for the author bio, or it must be based on a relationship to the current page. In either case, Views caching is disabled."

Since the view is not cached, and the view will have to fire even if there is no post relationship, my sense was that this could lead to a material increase in load.

I would ideally have thought that if there was no content to display, the view would not get fired at all.

I had a couple of follow-up questions:
(a) Is it possible to assess what is the performance hit of a non-cached view with no data being fired?
(b) For a site, which has a large number of posts without a relationship, and only some posts with a relationship, is it advisable to not use post relationships to avoid recurring firing of non-cached views with no results.

#1190361

I had another follow up to the previous 2 raised:
(c) I am not sure if there is really that large a performance hit of many empty views constantly firing, but is a better solution to show related content for the few posts that have related content via a view that uses post ids as an argument to show the related content information ... this is much more manual work, but may be a workaround that can work

#1190368

There is a logic problem, since view's result isn't cached, if you don't query database, you will not know if there is any result.

And as the document I mentioned above, if your view's settings satisfy those criteria, then view's result will be cached.

a) If there is no result found, even it is a non-cached view, it should not conduct the performance problem than other normal query.
b) And the post type relationship should not conduct performance problem than other normal query.

I suggest you test it in your website, check if there is any performance problem, then feedback the problem.