thedude
Well-known member
I'm attaching an updated RecentThreads.php file that eliminates unnecessary queries if you use the RecentThreads block with XenPorta.
Note: We've only tested it with XenForo 1.3
Instructions (again, only been tested with XF 1.3):
1. Make a backup copy of <xenforo install folder>/library/EWRporta/Block/RecentThreads.php
2. Extract the attached ZIP and copy the RecentThreads.php in the zip to <xenforo install folder>/library/EWRporta/Block/, overwriting the existing RecentThreads.php
Details
We use XenPorta's RecentThreads block on our site to show the last xx updated threads. We noticed a huge amount of added queries that this block was adding to the query count, compared to what XF's built in "New Posts" was adding. We found the issue and fixed it. Our front page queries have dropped equal to the number of threads we have set RecentThreads to show (eg. RecentThreads set to show 20 threads, queries dropped by 20 with this file).
Turns out the original RecentThreads.php included XenPorta 1.6 was calling the canViewThreadAndContainer function (which verifies whether the visitor can view a thread) without specifying the node permissions, which made that function call getContentPermissionsForItem down the stack, forcing an additional query. This was happening for each thread processed in the main RecentThreads loop. Fortunately one of the columns included with the main thread query is 'node_permission_cache', which gives us the permissions to pass to canViewThreadAndContainer, eliminating the need for that extra query per thread.
I'm guessing the ability to pass permissions to canViewThreadAndContainer may not have been implemented in XenForo when @Jaxel originally wrote this add-on, otherwise he would have implemented it at the time, so this is a just a little housekeeping to the file.
See this post for how to enable debug mode just for your IP, and check your query count (bottom of the each page, once you enable debug mode).
Note: We've only tested it with XenForo 1.3
Instructions (again, only been tested with XF 1.3):
1. Make a backup copy of <xenforo install folder>/library/EWRporta/Block/RecentThreads.php
2. Extract the attached ZIP and copy the RecentThreads.php in the zip to <xenforo install folder>/library/EWRporta/Block/, overwriting the existing RecentThreads.php
Details
We use XenPorta's RecentThreads block on our site to show the last xx updated threads. We noticed a huge amount of added queries that this block was adding to the query count, compared to what XF's built in "New Posts" was adding. We found the issue and fixed it. Our front page queries have dropped equal to the number of threads we have set RecentThreads to show (eg. RecentThreads set to show 20 threads, queries dropped by 20 with this file).
Turns out the original RecentThreads.php included XenPorta 1.6 was calling the canViewThreadAndContainer function (which verifies whether the visitor can view a thread) without specifying the node permissions, which made that function call getContentPermissionsForItem down the stack, forcing an additional query. This was happening for each thread processed in the main RecentThreads loop. Fortunately one of the columns included with the main thread query is 'node_permission_cache', which gives us the permissions to pass to canViewThreadAndContainer, eliminating the need for that extra query per thread.
I'm guessing the ability to pass permissions to canViewThreadAndContainer may not have been implemented in XenForo when @Jaxel originally wrote this add-on, otherwise he would have implemented it at the time, so this is a just a little housekeeping to the file.
See this post for how to enable debug mode just for your IP, and check your query count (bottom of the each page, once you enable debug mode).