Skip Navigation

[Resolved] Is there a more efficient way to set up this query?

This support ticket is created 5 years, 7 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 5 replies, has 2 voices.

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

Assisted by: Luo Yang.

Author
Posts
#1231962

LCR

Thanks,

After taking a look today, I think because our rate limit was hit, it only appeared that the caching was broken. For example, toolset maps would try to query Google for a location, but the API call would fail, and then toolset maps would be unable to cache a result, so the next time we hit the page, it would try all over again and keep failing.

Since our rate limit reset overnight, it looks like the cache populated successfully and is working as intended (not querying Google Maps unless it needs to).

Our biggest issue now is that the processing time on the backend is around 8-9 seconds for this page (we're monitoring using the Query Monitor plugin). If we remove the maps components, it only takes a 2-3 seconds to load. It seems like most of the processing time is taken up by a nested view. The outer view populates the location, and the inner view retrieves relationships between the given location and a related people post type (the people who live in these locations). The relationship data helps us populate map marker info window. Is there a more efficient way to set up this query? Would it be possible to query all of the relationship data at once rather than for each location, if that makes sense?

Thanks for the tips regarding the Debug View. One thing I can say right now is that on a page without the Toolset map, the debug opens a popup window just fine, so I'm not sure what's different other than the toolset components in use on the problem page.

#1232026

Hello,

I assume we are talking about this:
Two post types:
- Location( with a custom address field)
- People

One-to-many relationship between "Location" and "People".

So some people are using the same address value.

If it is, you can try just only one post view:
- Query posts of child "People" post type
- In view's loop, display "People" post information + address field value of related "Location" post
See our document:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-one-related-item-parent

#1232249

LCR

Hi Luo,

This is actually a many-to-many relationship. We have two main post types:
- Person
- Location

Many people can live in a given location, and a location can have many people living in it.

We then have a relationship post type, Person-Location, that contains data for the timespans in which people lived in the locations.

So Person A might live in Location X from 1800 to 1802, then Location Y from 1803 to 1804.
Person B might live in Location X from 1803 to 1804, then Location Y from 1805 to 1810.

We need to get each of the locations for the map view. Then for each location, we need to get the timespans for each location-person combination. That data will be displayed in the marker info window.

For example, hovering over the marker for Location X should show:
Person A (1800-1802)
Person B (1803-1804)

And hovering over the marker for Location Y should show:
Person A (1803-1804)
Person B (1805-1810)

Thanks for your help!

#1232573

Since you are using many-to-many relationships, so the nested view is required in this case:
- One "Person" post can connect with "Location" posts
- One "Location" post can connect with "Person" posts

see the document I mentioned above:
https://toolset.com/documentation/post-relationships/how-to-display-related-posts-with-toolset/#displaying-many-related-items

You will need to setup a child post view to query other related posts

I don't think there is other better workaround to query all of the relationship data at once(single post view).

You might consider add pagination to the parent post view, it can load few "Location" posts at the same time:
https://toolset.com/documentation/user-guides/views-pagination/

#1232801

LCR

Thanks,

After further investigation, it appears to be that even just loading the location data on its own into markers, without even trying to get related data, is quite inefficient. We have experimented with about 100 records, which should not take much time to process on the server, and it took over 10 seconds to begin sending data to the browser. There should be some way to speed that up!

Is it possible to query the data asynchronously from the client via JS, perhaps? Then at least we could have the page loaded and show a progress bar or spinner while the locations and other info load.

#1233106

For the new question:
Is it possible to query the data asynchronously from the client via JS, perhaps?

Unfortunately, there isn't such a built-in feature within Views plugin, you might consider adding pagination to your view:
https://toolset.com/documentation/user-guides/views-pagination/

And I don't think querying 100 posts will conduct the performance problem for an ordinary webserver, is it the problem of Google map API limitation?

If it is not, I suggest you check these:
1) Make sure you are using the latest version of Toolset plugins, you can download them here:
https://toolset.com/account/downloads/

2) In case it is a compatibility problem, please deactivate other plugins, and switch to wordpress default theme 2019, deactivate all Custom code snippets, and test again

If you are using search form in that post view, 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.