Bob
Well-known member
That widget is made with the Image Gallery renderer for the [bd] Widget Framework that comes with Showcase.
Yeah,That widget is made with the Image Gallery renderer for the [bd] Widget Framework that comes with Showcase.
# Time: 130817 4:36:26
# User@Host: <redacted>[<redacted>] @ localhost []
# Query_time: 8.823284 Lock_time: 0.000019 Rows_sent: 5 Rows_examined: 1830082
SET timestamp=1376732186;
SELECT attachment.*, attachment_data.*^M
,^M
post.thread_id,^M
thread.*^M
FROM xf_attachment AS attachment^M
INNER JOIN xf_attachment_data AS attachment_data ON^M
(attachment_data.data_id = attachment.data_id)^M
^M
INNER JOIN xf_post AS post ON^M
(post.post_id = attachment.content_id)^M
LEFT JOIN xf_thread AS thread ON^M
(thread.thread_id = post.thread_id)^M
WHERE (attachment.content_type = 'post')AND (thread.node_id IN ('8', '854', '855', '856', '857', '328', '96', '343', '462', '344', '58', '345', '463', '346', '72', '347', '461', '348', '292', '349', '460', '350', '86', '351', '464', '352', '339', '385', '649', '650', '651', '652', '665', '666', '667', '668', '57', '342', '522', '623', '639', '640', '641', '624', '625', '626', '675', '629', '698', '630', '237', '11', '95', '26', '628', '709', '612', '613', '658', '661', '660', '659', '662', '663', '620', '634', '635', '636', '637', '638', '671', '686', '234', '170', '19', '20', '21', '82', '83', '94', '76', '22', '23', '619', '687', '688', '691', '692', '693', '694', '690', '689', '647', '656', '677', '679', '680', '657', '669', '678', '813', '681'))AND (attachment_data.thumbnail_width != 0)^M
ORDER BY attachment_data.upload_date DESC^M
LIMIT 5;
$fetchOptions += array(
'limit' => $limit,
'order' => 'recent'
);
$fetchOptions += array(
'limit' => $limit
);
Before:If you're in agreement...
I believe from the query that you're using recent attachments rather than random... and if that's the case, IMHO, the ordering by upload_date isn't important. If it's the most recent 5, then that 5 will be in an appropriate order already.
So...
In RecentAttachmentsBlock/Listener.php change Line 53 from:
PHP:$fetchOptions += array( 'limit' => $limit, 'order' => 'recent' );
to:
PHP:$fetchOptions += array( 'limit' => $limit );
From my tests, albeit with only a few attachments, the run time for the query is considerably faster.
Let me know how it works in your environment.
INNER JOIN xf_attachment_data AS attachment_data ON
LEFT JOIN xf_attachment_data AS attachment_data ON
I also replacedYep.
So change line 63 of RecentAttachmentsBlock/Model/Attachment.php
From:PHP:INNER JOIN xf_attachment_data AS attachment_data ON
To:PHP:LEFT JOIN xf_attachment_data AS attachment_data ON
Do that in conjunction with the previous code edit, and I think that's pretty optimised. Might be able to do a bit more in terms of caching -- especially when dealing with recent vs random.
INNER JOIN xf_post AS post ON
LEFT JOIN xf_post AS post ON
@Chris Deeming - just checked this again, and removing the order by date will get you the oldest attachments, not the latest.If you're in agreement...
I believe from the query that you're using recent attachments rather than random... and if that's the case, IMHO, the ordering by upload_date isn't important. If it's the most recent 5, then that 5 will be in an appropriate order already.
So...
In RecentAttachmentsBlock/Listener.php change Line 53 from:
PHP:$fetchOptions += array( 'limit' => $limit, 'order' => 'recent' );
to:
PHP:$fetchOptions += array( 'limit' => $limit );
From my tests, albeit with only a few attachments, the run time for the query is considerably faster.
Let me know how it works in your environment.
public function getAttachmentsWithAttachKey(array $conditions = array(), array $fetchOptions = array())
{
$whereConditions = $this->prepareAttachmentConditions($conditions, $fetchOptions);
$limitOptions = $this->prepareLimitFetchOptions($fetchOptions);
return $this->fetchAllKeyed($this->limitQueryResults(
'
SELECT attachment.*, attachment_data.*,
post.thread_id, thread.*
FROM xf_attachment AS attachment
LEFT JOIN xf_attachment_data AS attachment_data ON
(attachment_data.data_id = attachment.data_id)
LEFT JOIN xf_post AS post ON
(post.post_id = attachment.content_id)
LEFT JOIN xf_thread AS thread ON
(thread.thread_id = post.thread_id)
WHERE ' . $whereConditions . '
ORDER BY attachment.attachment_id DESC
', $limitOptions['limit'], $limitOptions['offset']
), 'attachment_id');
}
We use essential cookies to make this site work, and optional cookies to enhance your experience.