What's new
Xen Factory

Register today to become a member! Once signed in, you'll be able to start purchasing our products, ask questions, request support and suggest new ideas!

Bug Fixed Extra query added for every person on the "Who has read this thread" list

benFF

New Member
This really needs some optimization as that's horrific.

There is a DB query executed for every single person listed on the "Who has read this thread" list. If you keep that list short maybe it's ok, but on mine I have elected to show all, which means this number can get massive. One of my threads has been read by over 600 people, which means on that page there are 600 extra DB queries!

All it's doing is this:

Code:
SELECT `xf_user`.*
FROM `xf_user`

WHERE (`xf_user`.`user_id` = 123)

This can surely be combined into one single query to get all users at once, no need to load them one by one.

On a large page it's doubling the page generation time.
 
Hi,
Can you give me more info please? like which list you talk for example

Regards
 
The "Who has read this thread" list at the bottom of the page.

This thread for example uses 568 queries overall! I thought maybe it was to do with the avatars, but it's still the same with a link list.

1640104273000.png
 
Yes i think is due to avatar
Can you tell me which addon/configuration you use to show queries ?
 
I have debug mode enabled but i can't show queries oO. Where do you see them ?

Edit: i see them, i used an addon to enable/disable debug mode but it doesn't show queries.
I investigate about this and i go back when i see something ;)
 
Not really wanting to do that - you can surely just run it yourself on your own forum.

It's one extra query for any user who doesn't have a post on the current page, if that's a clue.

Thinking about it, is it possible that xF automatically scans through all user links on a page?
 
i will create many user on my dev forum and i will investigate this.
Can you just screen me which options you have select for this addon please ?
 
Ok, I've found it.

It's in _data\templates.xml

Line 42
Code:
<xf:avatar user="$threadRead.User" size="xs" />
and 50
Code:
<li><xf:username user="$threadRead.User" rich="true" /></li>

Both these commands will cause an extra query for the user to be executed.
 
In src/addons/XFA/WhoReadThisThread/XF/Entity/Thread.php file can you replace:

PHP:
/** @var FinderCollection $finderCollection */
$finderCollection = $this->WRTRead;

$threadReadCollection = $finderCollection->toArray();

By:
PHP:
$threadReadCollection =  $this->finder('XFA\WhoReadThisThread:ThreadRead')->where([
    'thread_id' => $this->thread_id,
])->with('User')->fetch()->toArray();

And tell me if issue is fix or not. If yes, i will release a new version
 
Nope, back up to 558 queries again. Both on main and test machine.

But that file you told me to change, is back to how it was before ...
 

From bespoke add-on development to complex integrations and specialized enhancements, we offer a range of XenForo development services designed to help your community thrive.

Start discussing your needs
Back
Top
Cart