504 Time-Out issue
-
Hello
Thanks to your help, I got a (quite) complex gallery request:
[mla_gallery posts_per_page=99 orderby=rand]
tax_query=”array(
‘relation’ => ‘AND’,
array(
‘taxonomy’=>’attachment_category’,
‘field’=>’slug’,
‘terms’=> array( ‘cat1’ ),
‘operator’ => ‘IN’,
),
array(
‘taxonomy’=>’attachment_category’,
‘field’=>’slug’,
‘terms’=> array( ‘cat2’ ),
‘operator’ => ‘NOT IN’,
)
)”
[/mla_gallery]The problem now is: Since there are a lot pictures in those categories, the requests needs too much time and results in a 504 Time-Out error message.
My questions: Any chance to tune that request? Or cache and refresh it more seldom? I also read something about direct SQL requests, but cant find it anymore. May that be a solution?
Thanks for your help
Daniel
-
Thanks for your question. I am traveling until 10/26 but I will investigate this as soon as I am back at my development system.
Thanks for your patience while I was on the road. I’m back and getting caught up and ready to give your application some attention. Your suspicion that some tuning or direct SQL would improve things is correct. By default,
[mla_gallery]relies on the WordPressWP_Queryclass for database access. For some queries, such as those that involve taxonomies, a few simplifying assumptions can make a difference.For comparison, here is the SQL query generated by your shortcode parameters:
SELECT SQL_CALC_FOUND_ROWS mladev_posts.ID FROM mladev_posts LEFT JOIN mladev_term_relationships ON (mladev_posts.ID = mladev_term_relationships.object_id) LEFT JOIN mladev_posts AS p2 ON (p2.ID = p2.ID) WHERE 1=1 AND ( mladev_term_relationships.term_taxonomy_id IN (167,184) AND mladev_posts.ID NOT IN ( SELECT object_id FROM mladev_term_relationships WHERE term_taxonomy_id IN (26) ) ) AND (mladev_posts.post_mime_type LIKE 'image/%') AND mladev_posts.post_type = 'attachment' AND (((mladev_posts.post_status = 'inherit') OR (mladev_posts.post_status = 'inherit' AND (p2.post_status = 'inherit')))) GROUP BY mladev_posts.ID ORDER BY RAND() LIMIT 0, 99Note the tests for
mladev_posts.post_status = 'inherit'andmladev_posts.post_mime_type LIKE 'image/%'. If your application uses the Att. Category taxonomy exclusively for image attachments these tests are not required. In other words, can we assume that the only items assigned to “cat1” and “cat2” are image attachments? If so, a simpler query is possible.Let me know if those assumptions are valid and I will work something up for your testing.
Hey David
Welcome home again and thanks for the reply! Yep, the querry is only for images and the categories have only images assigned. I think, that makes things easier…
Thanks for your work!
DanielI have completed an enhancement to one of the MLA example plugins that should meet your requirements. You wrote “I also read something about direct SQL requests, but can’t find it anymore.” You may have found one of these earlier topics:
Gallery page with many images takes too long to load
MLATaxQuery with keyword search and pagination
REALLY Slow Queries…….. Help! 🙂
As you can see, taxonomy queries have been a performance issue for some time. These earlier topics inspired the “MLA Tax Query Example” plugin, which takes advantage of the simplifying assumption that the
attachment_categorytaxonomy is used exclusively to assigning terms to Media Library items. If you install and activate the example plugin you can change your shortcode to something like:[mla_gallery posts_per_page=99] my_custom_sql="attachment_category='cat1,/cat2' include_children=true orderby=rand" post_mime_type=all [/mla_gallery]In the above example:
- The
my_custom_sqlparameter activates the example plugin and contains the special sub-parameters it uses for its part of the job. attachment_category='cat1,/cat2'replaces thetax_queryin your original shortcode.- The ‘cat1,/cat2’ values are the terms you want to filter on. You can have as many terms as you need.
- The slash preceding
cat2assigns it to the “NOT IN” part of the query. - The
include_children=trueparameter matches the default used by the originaltax_query. You can omit it if your terms do not have any lower-level children you want to add to the list. orderby=randmust be moved inside themy_custom_sqlparameter because it affects the queries required.post_mime_type=allremoves the test that returns only image types. If you know that only images are assigned to your terms, leave it in. If you get non-image items in your results, remove this parameter to filter them out.
I have uploaded a new MLA Development Version dated 20171029 that contains the enhanced “MLA Tax Query Example” plugin. It would be great if you can install the Development Version and example plugin and do some testing of your own.
To get the Development Version, click this link to download the Development Version ZIP archive:
https://downloads.wordpress.org/plugin/media-library-assistant.zip
Once you have the ZIP archive on your system:
- Login to your site’s Admin area and navigate to Plugins/Installed Plugins.
Find Media Library Assistant and deactivate it. - Find Media Library Assistant and delete it. You will not lose any settings.
- Go to Plugins/Add New.
- Click “Upload Plugin”, to the right of the Add Plugins title.<br>”Browse…” to the location of the ZIP Archive and click on it.
- Click “Install Now”, to the right of “Browse…”
- When the install completes, click “Activate Plugin” at the bottom of the screen.
- When the activation completes, go back to the Plugins/Installed Plugins screen.
- Scroll down to “Media Library Assistant” and look for a date like “20171029” at the start of the Description. That’s how you know you have a Development Version. You can also go to the Settings/Media Library Assistant submenu and see the date stamp in the heading.
That’s it. I don’t change the version number of the Development Version, so you will be notified when the next official version comes out and the normal update process will continue to work.
To install the example plugin, navigate to the Settings/Media library Assistant Documentation tab and click the “Example Plugins” button. You will see a table that lists all the example plugins and gives you a “one-click” action for installing them. Type “tax query” in the text box (including the quotes) and click “Search Plugins” to filter the table. You are looking for “MLA Tax Query Example” example plugin. Find that plugin and hover over the title in the left-most column. Click the “Install” rollover action, then go to the WordPress Plugins/Installed Plugins submenu and activate it as you would any other plugin.
Let me know if you have any problems with the above suggestions.
OMG thats what I call a lean code! Thank you very much! It works perfectly without any problems! Issue solved :o)
Cheers
DanielThanks for the kind words and for the happy news confirming the improvements. As you can see, taxonomy queries can often benefit from the special aspects of each application.
I am leaving this topic resolved, but please update it if you have any other problems or further questions about taxonomy issues in your application.
- The
The topic ‘504 Time-Out issue’ is closed to new replies.