• Resolved davidjhk

    (@davidjhk)


    Hello,

    My site has several gallery pages with different categories.
    It was OK when I first set up the pages, but as number of images increases, the page loading is getting slower.
    For example, a category with 1,500 images takes 21 seconds to load, while a category with 400 images takes 7 seconds.
    Both category gallery shows only 20 images per page but it looks like that the speed is related to the whole number of images in the category.
    Is there any way I can make the pages load faster regardless of the number of images in the category?

    Here is the shortcode I used for the gallery page.

    [mla_gallery post_parent=all attachment_category=’landscape’ posts_per_page=20 mla_caption='{+title+}<br />{+caption+}’ post_mime_type=image size=medium orderby=’menu_order DESC,ID DESC’]
    [mla_gallery post_parent=all attachment_category=’landscape’ posts_per_page=20 post_mime_type=image mla_output=’paginate_links,prev_next’ orderby=’menu_order DESC,ID DESC’]

    with best regards,
    David Joo

Viewing 8 replies - 1 through 8 (of 8 total)
  • What’s your average image size, in pixel dimensions and kb? I know that my setup is loading the full size image and using the browser to scale, but you may need to specify to load thumbnails instead, if you’re not already doing so.

    Thread Starter davidjhk

    (@davidjhk)

    Hi Greg,

    Here is the website URL.
    https://roynjanephoto.com/

    The average image size is…

    Full size : 1000 x 668
    Thumbnail -> Medium Large : 768 x 513

    Using thumbnail is not an option because I didn’t want to show the cropped image as it will destroy the original ratio.

    When fully loaded, total size of a page with 20 thumbnails + header images is around 4MB.

    It is very fast to load a page when cache is applied.
    But for uncached page, it is very slow to load.

    You can try a page which is not cached yet, ie.,
    https://roynjanephoto.com/landscape/?mla_paginate_current=14
    https://roynjanephoto.com/landscape/?mla_paginate_current=15
    https://roynjanephoto.com/landscape/?mla_paginate_current=16
    * You can change the mla_paginate_current parameter to open another uncached pages.

    I doubt that when MLA plugin retrieve a gallery, it seems like querying all the records in the same category, instead of just counting the number of items.

    • This reply was modified 7 years, 8 months ago by davidjhk.
    • This reply was modified 7 years, 8 months ago by davidjhk.
    • This reply was modified 7 years, 8 months ago by davidjhk.
    • This reply was modified 7 years, 8 months ago by davidjhk.
    Plugin Author David Lingren

    (@dglingren)

    Thanks for your question, for the shortcode text and for supplying the additional details in response to Greg’s question.

    I entered your shortcode text on my test system and had a look at the database activity they generate. I believe the performance issues you are experiencing are related to the database queries required to get the results you want.

    WordPress taxonomies are a powerful tool but they can require complex queries to get the desired results. MLA uses the WordPress WP_Query class to query the database. That’s usually the best way to get results, but in cases like yours it can have performance problems.

    You wrote “it seems like querying all the records in the same category … That is true and it is part of the problem. Your shortcode includes orderby=’menu_order DESC,ID DESC’, which means that all of the items in the entire category must be retrieved and sorted before the posts_per_page=20 can be applied. There is no way of knowing which 20 items are right without sorting them all.

    Another potential problem is that all of the rows in the posts table must be joined to the term_relationships table to find which items have been assigned to the category you want. The performance on this step is affected by the total number of posts/pages/attachments and the total number of term assignments.

    Since the Media Library items share the posts table with posts and pages, additional query logic is required to filter out just the attachments, and additional tests are made for post_status and post_mime_type.

    If your application has certain restrictions you can improve performance a lot by using custom SQL queries instead of relying on WP_Query. For example, if you know that the terms you are filtering on are only assigned to images you can eliminate the tests for post_type, post_status and post_mime_type. There are several earlier support topics along lines similar to yours:

    How to use custom taxonomy in my_custom_sql

    REALLY Slow Queries…….. Help! ??

    Slow queries

    There is an MLA example plugin, “MLA tax query Example”, that was developed to resolve these topics. You may find it works in your application. If you would like to try installing the example plugin and working with it, let me know and I will give you more specific help with that.

    I hope the above explanations and earlier topics shed some light on your performance issues. I will leave this topic unresolved until I hear back from you. Thanks for your interest in the plugin.

    Thread Starter davidjhk

    (@davidjhk)

    Hi David,

    Thank you for the quick response.
    I caught your point.
    Can I try the “MLA tax query Example” plugin?

    Thread Starter davidjhk

    (@davidjhk)

    Hi David,

    I found that the MLA tax query example plugin from the examples folder in MLA Plugin Folder.
    So I installed the plugin and played around with it.
    Now I found a way to make my gallery super fast but found one problem.
    It has a parameter “orderby” and “order” and it seems working weirdly.
    Here is my test code.

    [mla_gallery post_parent="all" my_custom_sql="attachment_category=nature" posts_per_page="20" mla_caption="{+title+}<br />{+caption+}" size="medium" orderby="id" order="DESC" mla_debug="true"]
    [mla_gallery post_parent="all" my_custom_sql="attachment_category=nature" posts_per_page="20" mla_caption="{+title+}<br />{+caption+}" size="medium" orderby="id" order="DESC" mla_output="paginate_links" ]

    And here is the actual web page including this shortcode.

    https://roynjanephoto.com/test-test/

    I expected all the images being sorted in reverse order by ID field for pagination.
    But the sorting happened AFTER pagination not BEFORE pagination.
    which means…

    Let’s say I have 1,2,3,4……40.

    My expected order was 40,39,38…21 on page 1.
    And 20,19,18…1 on page 2.

    But actual result was 20,19,18….1 on page 1
    And 40,39,38….21 on page 2.

    Any suggestion?

    2. Another question is…

    It seems the “author_name” parameter doesn’t work well with pagination.
    The filtering by author name happens after pagination not before pagination.
    If there are 10 images by an author “goldenpond” within ID 1~20,
    and there are 10 more images within ID page 21~40,
    The page 1 only shows 10 images on page 1.
    But it should show all 20 images on page 1 because ‘posts_per_page’ is set to 20.

    • This reply was modified 7 years, 8 months ago by davidjhk.
    • This reply was modified 7 years, 8 months ago by davidjhk.
    • This reply was modified 7 years, 8 months ago by davidjhk.
    • This reply was modified 7 years, 8 months ago by davidjhk.
    • This reply was modified 7 years, 8 months ago by davidjhk.
    Plugin Author David Lingren

    (@dglingren)

    Thanks for your updates and for taking the time to install and experiment with the example plugin.

    You can solve the sorting problem by moving your orderby and order parameters inside the my_custom_sql parameter. Try changing your shortcodes to something like this:

    [mla_gallery my_custom_sql="attachment_category=nature" orderby=id order=DESC  posts_per_page="20" mla_caption="{+title+}<br />{+caption+}" size="medium"]
    [mla_gallery my_custom_sql="attachment_category=nature  orderby=id order=DESC" posts_per_page="20" mla_output="paginate_links" ]
    

    Note that I have removed some unnecessary parameters from the shortcodes you posted.

    Regarding your second question, you are right; any parameters outside the my_custom_sql parameter are applied after the custom SQL queries are complete. The comments in the plugin code include:

    * The “my_custom_sql” parameter accepts these query arguments:
    * – one or more taxonomy=slug(,slug)… arguments, which will be joined by OR
    * – include_children=true
    * – order and/or orderby

    Only the three parameters in the comment are processed by the custom SQL functions. If filtering by author is important for your application I can see if adding that parameter to the plugin is feasible. Filtering by post_author, i.e. the author’s ID number, might be possible.

    Let me know if the sorting suggestions are helpful and if you need filtering by author.

    Thread Starter davidjhk

    (@davidjhk)

    Hi David,

    Thank you for the help.
    Now the sorting works as expected after following your suggestion.
    Filtering by author is one of the key features for the web site.
    So adding it to the plugin will be a great help to me.

    p.s. I just want to let you know that I have donated to Community Partners for this wonderful plugin via PayPal.

    • This reply was modified 7 years, 8 months ago by davidjhk.
    • This reply was modified 7 years, 8 months ago by davidjhk.
    Plugin Author David Lingren

    (@dglingren)

    Thank you for your generous donation in support of our fair trade work. Donations, reviews and positive feedback are great motivators to keep working on the plugin and supporting its users!

    Thanks as well for working with me offline to test an updated version of the MLA Tax Query Example plugin that adds the “author” filtering. I will add the updated plugin to my next regular MLA version. With the updated plugin you can code your shortcodes as follows:

    [mla_gallery post_parent="all" my_custom_sql="attachment_category=nature author=6 orderby=id order=DESC" posts_per_page="20" mla_caption='{+title+}<br />{+caption+}' size="medium"]
    
    [mla_gallery post_parent="all" my_custom_sql="attachment_category=nature author=6 orderby=id order=DESC" posts_per_page="20" mla_output="paginate_links,prev_next"]
    

    I am marking this topic resolved, but please update it if you have any problems or further questions regarding the MLA Tax Query Example plugin. Thanks again for your support and your interest in the plugin.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Gallery page with many images takes too long to load’ is closed to new replies.