Opened 5 months ago

Last modified 3 days ago

#23044 new enhancement

adjacent_image_link() needs optimization

Reported by: markjaquith Owned by:
Priority: normal Milestone: 3.6
Component: Query Version: 3.5
Severity: major Keywords:
Cc: xoodrew@…, ADAMSILVERSTEIN@…, dromsey@…, hardyy

Description

adjacent_image_link() is really slow and stupid. It queries for all of the images attached to that post. And then it picks the previous or next one in PHP. And there's no caching, so you'll typically get this happening three times on an attachment page, (image [linked to next], prev link, next link).

We should actually just make the query grab the ONE image we want.

Attachments (1)

23044.patch (2.4 KB) - added by hardyy 4 weeks ago.

Download all attachments as: .zip

Change History (10)

Talked with Nacin about this. This may end up being moot if we solve the bigger issue of determining the correct prev/next image, considering that images don't have to be in parent-post-bounded galleries.

In the meantime, this is the plugin I wrote to make it so that it doesn't query everything:

https://gist.github.com/4357848

#22903 was marked as a duplicate.

  • Cc xoodrew@… added
  • Cc ADAMSILVERSTEIN@… added
  • Cc dromsey@… added
  • Version changed from trunk to 3.5

hardyy4 weeks ago

Added an optional argument in get_children() so that it returns numerical array containing only IDs of elements. Easier to return than array of objects.
Also makes it easier to search through in-built array functions.
in_array() is added to make sure loop don't skip in some cases.
If i have done any mistake, feel free to notify me.

  • Cc hardyy added

comment:9   westi3 days ago

As well as the major optimisation of an improved query here there is a simple optimisation we could use to improve the performance of this on sites with a large number of images attached to a post.

If we switch from get_children to get_posts we can avoid calling update_post_cache on every attachment post for every query.

Note: See TracTickets for help on using tickets.