Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
It is a relatively expensive function with a db query and it can get called multiple times on a page load. The approach I've taken with this patch is to only statically cache if module and nid are known and the other function args are defaults. If they are not defaults, I don't cache. This hits the vast majority of cases and avoids redundant queries.
Comment | File | Size | Author |
---|---|---|---|
#4 | links-cache.patch | 3.34 KB | robphillips |
#3 | links-cache.patch | 3.24 KB | robphillips |
links-cache.patch | 3.54 KB | robertDouglass |
Comments
Comment #1
chromeyellow CreditAttribution: chromeyellow commentedA good patch, but the underlying issue still may be the one noted at http://drupal.org/node/74016#comment-167964 ...
Briefly, links_load_links_for_node only needs to be called once, during the 'load' component on links_related_nodeapi. That loads the link info into the node object, after which it is available like everything else in a $node. However, as it stands the module persists in loading link data everytime it's needed, rather than grabbing the data from the node object.
Sys and I traded notes on this but it fell off the radar, buried in a comment in a 4.7 bug (that may have been a side-effect of all those unnecessary queries). Also, I had only had time to specifically analyse the links_related side of things.
At any rate, this patch would be useful failsafe - but the underlying code error still needs tending...
Comment #2
robphillips CreditAttribution: robphillips commentedThe patch above failed for the latest release for me, attached is just an updated patch that should update successfully.
Comment #3
robphillips CreditAttribution: robphillips commentedAttaching patch...
Comment #4
robphillips CreditAttribution: robphillips commentedHere is an updated patch which prevents a form error when updating an existing link.