SMFHacks.com
SMFHacks
Community Suite
SMF Gallery Pro
SMF Store
SMF Classifieds
Newsletter Pro
Downloads System Pro
Ad Seller Pro
Hacks and Mods
Latest SMF Hacks
TopTen Hacks
Styles and Themes
Add a Hack
Manage Hacks
Earn Money from Your Forum with these tips
SMF Theme Generator
SMF Package Parser
Free SMF Hosting
HostRocket Webhosting for SMF
Site Showcase
Search Forums
Advanced search
User
Welcome,
Guest
. Please
login
or
register
.
May 25, 2012, 01:41:09 pm
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Stats
Members
Total Members: 10073
Latest:
makablue
Stats
Total Posts: 28694
Total Topics: 4979
Online Today: 88
Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Users: 0
Guests: 70
Total: 70
SMFHacks.com
Forum
SMF Gallery Pro
Support
SMF Galllery causing MySQL to hang
0 Members and 1 Guest are viewing this topic.
« previous
next »
Pages:
[
1
]
Author
Topic: SMF Galllery causing MySQL to hang (Read 759 times)
spikeweb
Newbie
Offline
Posts: 35
SMF Galllery causing MySQL to hang
«
on:
January 25, 2012, 04:14:47 pm »
Running SMF Gallery for sometime already, I face an issue from a few days where MySQL server hangs due to a SMF Gallery query, as investigated by my sysadmin.
Here is the query wher forum1 is the database:
Query_time: 495 Lock_time: 0 Rows_sent: 11692 Rows_examined: 203822242
SELECT
COUNT(*) as total
FROM (forum1_gallery_pic as p, forum1_gallery_comment as com)
LEFT JOIN forum1_members AS m ON (m.ID_MEMBER = p.ID_MEMBER)
LEFT JOIN forum1_gallery_usersettings AS s ON (s.ID_MEMBER = m.ID_MEMBER)
LEFT JOIN forum1_gallery_log_mark_view AS v ON (p.ID_PICTURE = v.ID_PICTURE AND v.ID_MEMBER = 51080 AND v.user_id_cat = p.USER_ID_CAT)
WHERE ((s.private =0 || s.private IS NULL ) AND (s.password = '' || s.password IS NULL ) AND p.USER_ID_CAT !=0 AND p.approved =1) || (p.approved =1 AND p.USER_ID_CAT =0) AND com.ID_PICTURE = p.ID_PICTURE GROUP BY p.ID_PICTURE;
I have some more queries causing the same default. Available on demand but same structure.
Any idea of what could be the cause of the problem and how to correct it ?
THX a lot for your support,
Logged
SMFHacks
Administrator
Hero Member
Offline
Posts: 9680
Re: SMF Galllery causing MySQL to hang
«
Reply #1 on:
January 25, 2012, 04:18:18 pm »
Try this query changed the order run via phpmyadmin I want to see how many are rows are examined
Code:
explain SELECT
COUNT(*) as total
FROM (forum1_gallery_pic as p, forum1_gallery_comment as com)
LEFT JOIN forum1_members AS m ON (m.ID_MEMBER = p.ID_MEMBER)
LEFT JOIN forum1_gallery_usersettings AS s ON (s.ID_MEMBER = m.ID_MEMBER)
LEFT JOIN forum1_gallery_log_mark_view AS v ON (p.ID_PICTURE = v.ID_PICTURE AND v.ID_MEMBER = 51080 AND v.user_id_cat = p.USER_ID_CAT)
WHERE com.ID_PICTURE = p.ID_PICTURE AND ((s.private =0 || s.private IS NULL ) AND (s.password = '' || s.password IS NULL ) AND p.USER_ID_CAT !=0 AND p.approved =1) || (p.approved =1 AND p.USER_ID_CAT =0) GROUP BY p.ID_PICTURE;
Logged
spikeweb
Newbie
Offline
Posts: 35
Re: SMF Galllery causing MySQL to hang
«
Reply #2 on:
January 25, 2012, 04:25:50 pm »
Just ran and got this :
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE com ALL NULL NULL NULL NULL 2301 Using temporary; Using filesort
1 SIMPLE p ALL PRIMARY,USER_ID_CAT NULL NULL NULL 12100 Using where
1 SIMPLE m eq_ref PRIMARY PRIMARY 3 npnforum1.p.ID_MEMBER 1 Using index
1 SIMPLE s eq_ref PRIMARY PRIMARY 3 npnforum1.m.ID_MEMBER 1 Using where
1 SIMPLE v ref user_id_cat,id_picture,id_member id_picture 4 npnforum1.p.ID_PICTURE 7
Logged
SMFHacks
Administrator
Hero Member
Offline
Posts: 9680
Re: SMF Galllery causing MySQL to hang
«
Reply #3 on:
January 25, 2012, 04:29:30 pm »
Ok that might be the fix will make an update to the gallery 4.0 beta tonight with that change.
Logged
spikeweb
Newbie
Offline
Posts: 35
Re: SMF Galllery causing MySQL to hang
«
Reply #4 on:
January 25, 2012, 04:31:07 pm »
Please note that it is not 4.0 beta but 3.0.25
Any chance to get a fix for this specific release as we cannot upgrade to a beta release until it has passed our tests ...
Logged
SMFHacks
Administrator
Hero Member
Offline
Posts: 9680
Re: SMF Galllery causing MySQL to hang
«
Reply #5 on:
January 25, 2012, 04:39:32 pm »
I can probably provide a code change what SMF version are you using.
Logged
spikeweb
Newbie
Offline
Posts: 35
Re: SMF Galllery causing MySQL to hang
«
Reply #6 on:
January 26, 2012, 12:45:34 am »
SMF is 1.1.16
Logged
SMFHacks
Administrator
Hero Member
Offline
Posts: 9680
Re: SMF Galllery causing MySQL to hang
«
Reply #7 on:
January 26, 2012, 09:10:35 am »
Open Sources/Gallery.php
Find
Code:
function ListAll()
{
global $db_prefix, $user_info, $context, $txt, $ID_MEMBER, $mbname, $modSettings, $scripturl;
// Is the user allowed to view the gallery?
isAllowedTo('smfgallery_view');
if (!$context['user']['is_guest'])
$groupsdata = implode($user_info['groups'], ',');
else
$groupsdata = -1;
StoreGalleryLocation();
// Show top Tabs
TopButtonTabs();
$type = $_REQUEST['type'];
$context['sub_template'] = 'listall';
$orderby = 'desc';
if (isset($_REQUEST['orderby']))
{
if ($_REQUEST['orderby'] == 'desc')
$orderby = 'desc';
else
$orderby = 'asc';
}
if (allowedTo('smfgallery_manage'))
{
$wherestats = "
LEFT JOIN {$db_prefix}members AS m ON (m.ID_MEMBER = p.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_log_mark_view AS v ON (p.ID_PICTURE = v.ID_PICTURE AND v.ID_MEMBER = $ID_MEMBER AND v.user_id_cat = p.USER_ID_CAT)
WHERE p.approved =1";
}
else
$wherestats = "
LEFT JOIN {$db_prefix}members AS m ON (m.ID_MEMBER = p.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_usersettings AS s ON (s.ID_MEMBER = m.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_log_mark_view AS v ON (p.ID_PICTURE = v.ID_PICTURE AND v.ID_MEMBER = $ID_MEMBER AND v.user_id_cat = p.USER_ID_CAT)
LEFT JOIN {$db_prefix}gallery_catperm AS c ON (c.id_group IN ($groupsdata) AND c.id_cat = p.id_cat)
WHERE ((s.private =0 || s.private IS NULL ) AND (s.password = '' || s.password IS NULL ) AND p.USER_ID_CAT !=0 AND p.approved =1) || (p.approved = 1 AND p.user_id_cat = 0 AND (c.view IS NULL || c.view = 1)) ";
switch ($type)
{
case 'recent':
// Get total number of results
$result = db_query("
SELECT
COUNT(*) as total
FROM {$db_prefix}gallery_pic as p
$wherestats
", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$context['page_index'] = constructPageIndex($scripturl . '?action=gallery;sa=listall;type=' . $_REQUEST['type'] , $_REQUEST['start'], $row['total'], $modSettings['gallery_set_images_per_page']);
$context['start'] = $_REQUEST['start'];
$result = db_query("
SELECT
p.ID_PICTURE, p.commenttotal, p.totalratings, p.rating, p.filesize,
p.views, p.thumbfilename, p.title, p.ID_MEMBER, m.realName, p.date,
p.description, p.mature, v.ID_PICTURE as unread
FROM {$db_prefix}gallery_pic as p
$wherestats GROUP BY p.ID_PICTURE
ORDER BY p.ID_PICTURE $orderby
LIMIT $context[start], " . $modSettings['gallery_set_images_per_page']
, __FILE__, __LINE__);
$context['picture_list'] = array();
while($row = mysql_fetch_assoc($result))
{
$context['picture_list'][] = $row;
}
mysql_free_result($result);
$context['gallery_stat_title'] = $txt['gallery_stats_last'];
$context['page_title'] = $mbname . ' - ' . $txt['gallery_stats_last'];
break;
case 'comments':
// Get total number of results
$result = db_query("
SELECT
COUNT(*) as total
FROM {$db_prefix}gallery_pic as p
$wherestats
", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$context['page_index'] = constructPageIndex($scripturl . '?action=gallery;sa=listall;type=' . $_REQUEST['type'] . ';orderby=' . $orderby , $_REQUEST['start'], $row['total'], $modSettings['gallery_set_images_per_page']);
$context['start'] = $_REQUEST['start'];
$result = db_query("
SELECT
p.ID_PICTURE, p.commenttotal, p.totalratings, p.rating, p.filesize,
p.views, p.thumbfilename, p.title, p.ID_MEMBER, m.realName, p.date,
p.description, p.mature, v.ID_PICTURE as unread
FROM {$db_prefix}gallery_pic as p
$wherestats GROUP BY p.ID_PICTURE
ORDER BY p.commenttotal $orderby
LIMIT $context[start], " . $modSettings['gallery_set_images_per_page']
, __FILE__, __LINE__);
$context['picture_list'] = array();
while($row = mysql_fetch_assoc($result))
{
$context['picture_list'][] = $row;
}
mysql_free_result($result);
$context['gallery_stat_title'] = $txt['gallery_stats_mostcomments'];
$context['page_title'] = $mbname . ' - ' . $txt['gallery_stats_mostcomments'];
break;
case 'views':
// Get total number of results
$result = db_query("
SELECT
COUNT(*) as total
FROM {$db_prefix}gallery_pic as p
$wherestats
", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$context['page_index'] = constructPageIndex($scripturl . '?action=gallery;sa=listall;type=' . $_REQUEST['type'] . ';orderby=' . $orderby , $_REQUEST['start'], $row['total'], $modSettings['gallery_set_images_per_page']);
$context['start'] = $_REQUEST['start'];
$result = db_query("
SELECT
p.ID_PICTURE, p.commenttotal, p.totalratings, p.rating, p.filesize,
p.views, p.thumbfilename, p.title, p.ID_MEMBER, m.realName,
p.date, p.description, p.mature, v.ID_PICTURE as unread
FROM {$db_prefix}gallery_pic as p
$wherestats GROUP BY p.ID_PICTURE
ORDER BY p.views $orderby
LIMIT $context[start], " . $modSettings['gallery_set_images_per_page']
, __FILE__, __LINE__);
$context['picture_list'] = array();
while($row = mysql_fetch_assoc($result))
{
$context['picture_list'][] = $row;
}
mysql_free_result($result);
$context['gallery_stat_title'] = $txt['gallery_stats_viewed'];
$context['page_title'] = $mbname . ' - ' . $txt['gallery_stats_viewed'];
break;
case 'toprated':
$result = db_query("
SELECT
COUNT(*) as total
FROM {$db_prefix}gallery_pic as p
$wherestats
", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$context['page_index'] = constructPageIndex($scripturl . '?action=gallery;sa=listall;type=' . $_REQUEST['type'] . ';orderby=' . $orderby , $_REQUEST['start'], $row['total'], $modSettings['gallery_set_images_per_page']);
$context['start'] = $_REQUEST['start'];
$result = db_query("
SELECT
p.ID_PICTURE, p.commenttotal, p.totalratings, p.rating, p.filesize,
p.views, p.thumbfilename, p.title, p.ID_MEMBER, m.realName, p.date,
p.description, p.mature, v.ID_PICTURE as unread
FROM {$db_prefix}gallery_pic as p
$wherestats GROUP BY p.ID_PICTURE
ORDER BY p.rating $orderby
LIMIT $context[start], " . $modSettings['gallery_set_images_per_page']
, __FILE__, __LINE__);
$context['picture_list'] = array();
while($row = mysql_fetch_assoc($result))
{
$context['picture_list'][] = $row;
}
mysql_free_result($result);
$context['gallery_stat_title'] = $txt['gallery_stats_toprated'];
$context['page_title'] = $mbname . ' - ' .$txt['gallery_stats_toprated'];
break;
case 'random':
$result = db_query("
SELECT
COUNT(*) as total
FROM {$db_prefix}gallery_pic as p
$wherestats
", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$context['page_index'] = constructPageIndex($scripturl . '?action=gallery;sa=listall;type=' . $_REQUEST['type'] . ';orderby=' . $orderby , $_REQUEST['start'], $row['total'], $modSettings['gallery_set_images_per_page']);
$context['start'] = $_REQUEST['start'];
$result = db_query("
SELECT
p.ID_PICTURE, p.commenttotal, p.totalratings, p.rating, p.filesize,
p.views, p.thumbfilename, p.title, p.ID_MEMBER, m.realName, p.date,
p.description, p.mature, v.ID_PICTURE as unread
FROM {$db_prefix}gallery_pic as p
$wherestats GROUP BY p.ID_PICTURE
ORDER BY RAND() $orderby
LIMIT $context[start], " . $modSettings['gallery_set_images_per_page']
, __FILE__, __LINE__);
$context['picture_list'] = array();
while($row = mysql_fetch_assoc($result))
{
$context['picture_list'][] = $row;
}
mysql_free_result($result);
$context['gallery_stat_title'] = $txt['gallery_main_random'];
$context['page_title'] = $mbname . ' - ' .$txt['gallery_main_random'];
break;
case 'recentcomments':
$result = db_query("
SELECT
COUNT(*) as total
FROM ({$db_prefix}gallery_pic as p, {$db_prefix}gallery_comment as com)
$wherestats AND com.ID_PICTURE = p.ID_PICTURE GROUP BY p.ID_PICTURE
", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$context['page_index'] = constructPageIndex($scripturl . '?action=gallery;sa=listall;type=' . $_REQUEST['type'] . ';orderby=' . $orderby , $_REQUEST['start'], $row['total'], $modSettings['gallery_set_images_per_page']);
$context['start'] = $_REQUEST['start'];
$wherestats = "
LEFT JOIN {$db_prefix}members AS m ON (m.ID_MEMBER = p.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_usersettings AS s ON (s.ID_MEMBER = m.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_log_mark_view AS v ON (p.ID_PICTURE = v.ID_PICTURE AND v.ID_MEMBER = $ID_MEMBER AND v.user_id_cat = p.USER_ID_CAT)
LEFT JOIN {$db_prefix}gallery_catperm AS c ON (c.id_group IN ($groupsdata) AND c.id_cat = p.id_cat)
WHERE (((s.private =0 || s.private IS NULL ) AND (s.password = '' || s.password IS NULL ) AND p.USER_ID_CAT !=0 AND p.approved =1) || (p.approved = 1 AND p.user_id_cat = 0 AND (c.view IS NULL || c.view = 1))) ";
$result = db_query("
SELECT
max(com.ID_COMMENT) AS lastcomment, p.ID_PICTURE, p.commenttotal, p.totalratings, p.rating, p.filesize,
p.views, p.thumbfilename, p.title, p.ID_MEMBER, m.realName, p.date,
p.description, p.mature, v.ID_PICTURE as unread
FROM ({$db_prefix}gallery_pic as p, {$db_prefix}gallery_comment as com)
$wherestats AND com.ID_PICTURE = p.ID_PICTURE GROUP BY p.ID_PICTURE
ORDER BY lastcomment $orderby
LIMIT $context[start], " . $modSettings['gallery_set_images_per_page']
, __FILE__, __LINE__);
$context['picture_list'] = array();
while($row = mysql_fetch_assoc($result))
{
$context['picture_list'][] = $row;
}
mysql_free_result($result);
$context['gallery_stat_title'] = $txt['gallery_main_recentcomment'];
$context['page_title'] = $mbname . ' - ' . $txt['gallery_main_recentcomment'];
break;
}
}
Replace with
Code:
function ListAll()
{
global $db_prefix, $user_info, $context, $txt, $ID_MEMBER, $mbname, $modSettings, $scripturl;
// Is the user allowed to view the gallery?
isAllowedTo('smfgallery_view');
if (!$context['user']['is_guest'])
$groupsdata = implode($user_info['groups'], ',');
else
$groupsdata = -1;
StoreGalleryLocation();
// Show top Tabs
TopButtonTabs();
$type = $_REQUEST['type'];
$context['sub_template'] = 'listall';
$orderby = 'desc';
if (isset($_REQUEST['orderby']))
{
if ($_REQUEST['orderby'] == 'desc')
$orderby = 'desc';
else
$orderby = 'asc';
}
if (allowedTo('smfgallery_manage'))
{
$wherestats = "
LEFT JOIN {$db_prefix}members AS m ON (m.ID_MEMBER = p.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_log_mark_view AS v ON (p.ID_PICTURE = v.ID_PICTURE AND v.ID_MEMBER = $ID_MEMBER AND v.user_id_cat = p.USER_ID_CAT)
WHERE p.approved =1";
}
else
$wherestats = "
LEFT JOIN {$db_prefix}members AS m ON (m.ID_MEMBER = p.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_usersettings AS s ON (s.ID_MEMBER = m.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_log_mark_view AS v ON (p.ID_PICTURE = v.ID_PICTURE AND v.ID_MEMBER = $ID_MEMBER AND v.user_id_cat = p.USER_ID_CAT)
LEFT JOIN {$db_prefix}gallery_catperm AS c ON (c.id_group IN ($groupsdata) AND c.id_cat = p.id_cat)
WHERE ((s.private =0 || s.private IS NULL ) AND (s.password = '' || s.password IS NULL ) AND p.USER_ID_CAT !=0 AND p.approved =1) || (p.approved = 1 AND p.user_id_cat = 0 AND (c.view IS NULL || c.view = 1)) ";
switch ($type)
{
case 'recent':
// Get total number of results
$result = db_query("
SELECT
COUNT(*) as total
FROM {$db_prefix}gallery_pic as p
$wherestats
", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$context['page_index'] = constructPageIndex($scripturl . '?action=gallery;sa=listall;type=' . $_REQUEST['type'] , $_REQUEST['start'], $row['total'], $modSettings['gallery_set_images_per_page']);
$context['start'] = $_REQUEST['start'];
$result = db_query("
SELECT
p.ID_PICTURE, p.commenttotal, p.totalratings, p.rating, p.filesize,
p.views, p.thumbfilename, p.title, p.ID_MEMBER, m.realName, p.date,
p.description, p.mature, v.ID_PICTURE as unread
FROM {$db_prefix}gallery_pic as p
$wherestats GROUP BY p.ID_PICTURE
ORDER BY p.ID_PICTURE $orderby
LIMIT $context[start], " . $modSettings['gallery_set_images_per_page']
, __FILE__, __LINE__);
$context['picture_list'] = array();
while($row = mysql_fetch_assoc($result))
{
$context['picture_list'][] = $row;
}
mysql_free_result($result);
$context['gallery_stat_title'] = $txt['gallery_stats_last'];
$context['page_title'] = $mbname . ' - ' . $txt['gallery_stats_last'];
break;
case 'comments':
// Get total number of results
$result = db_query("
SELECT
COUNT(*) as total
FROM {$db_prefix}gallery_pic as p
$wherestats
", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$context['page_index'] = constructPageIndex($scripturl . '?action=gallery;sa=listall;type=' . $_REQUEST['type'] . ';orderby=' . $orderby , $_REQUEST['start'], $row['total'], $modSettings['gallery_set_images_per_page']);
$context['start'] = $_REQUEST['start'];
$result = db_query("
SELECT
p.ID_PICTURE, p.commenttotal, p.totalratings, p.rating, p.filesize,
p.views, p.thumbfilename, p.title, p.ID_MEMBER, m.realName, p.date,
p.description, p.mature, v.ID_PICTURE as unread
FROM {$db_prefix}gallery_pic as p
$wherestats GROUP BY p.ID_PICTURE
ORDER BY p.commenttotal $orderby
LIMIT $context[start], " . $modSettings['gallery_set_images_per_page']
, __FILE__, __LINE__);
$context['picture_list'] = array();
while($row = mysql_fetch_assoc($result))
{
$context['picture_list'][] = $row;
}
mysql_free_result($result);
$context['gallery_stat_title'] = $txt['gallery_stats_mostcomments'];
$context['page_title'] = $mbname . ' - ' . $txt['gallery_stats_mostcomments'];
break;
case 'views':
// Get total number of results
$result = db_query("
SELECT
COUNT(*) as total
FROM {$db_prefix}gallery_pic as p
$wherestats
", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$context['page_index'] = constructPageIndex($scripturl . '?action=gallery;sa=listall;type=' . $_REQUEST['type'] . ';orderby=' . $orderby , $_REQUEST['start'], $row['total'], $modSettings['gallery_set_images_per_page']);
$context['start'] = $_REQUEST['start'];
$result = db_query("
SELECT
p.ID_PICTURE, p.commenttotal, p.totalratings, p.rating, p.filesize,
p.views, p.thumbfilename, p.title, p.ID_MEMBER, m.realName,
p.date, p.description, p.mature, v.ID_PICTURE as unread
FROM {$db_prefix}gallery_pic as p
$wherestats GROUP BY p.ID_PICTURE
ORDER BY p.views $orderby
LIMIT $context[start], " . $modSettings['gallery_set_images_per_page']
, __FILE__, __LINE__);
$context['picture_list'] = array();
while($row = mysql_fetch_assoc($result))
{
$context['picture_list'][] = $row;
}
mysql_free_result($result);
$context['gallery_stat_title'] = $txt['gallery_stats_viewed'];
$context['page_title'] = $mbname . ' - ' . $txt['gallery_stats_viewed'];
break;
case 'toprated':
$result = db_query("
SELECT
COUNT(*) as total
FROM {$db_prefix}gallery_pic as p
$wherestats
", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$context['page_index'] = constructPageIndex($scripturl . '?action=gallery;sa=listall;type=' . $_REQUEST['type'] . ';orderby=' . $orderby , $_REQUEST['start'], $row['total'], $modSettings['gallery_set_images_per_page']);
$context['start'] = $_REQUEST['start'];
$result = db_query("
SELECT
p.ID_PICTURE, p.commenttotal, p.totalratings, p.rating, p.filesize,
p.views, p.thumbfilename, p.title, p.ID_MEMBER, m.realName, p.date,
p.description, p.mature, v.ID_PICTURE as unread
FROM {$db_prefix}gallery_pic as p
$wherestats GROUP BY p.ID_PICTURE
ORDER BY p.rating $orderby
LIMIT $context[start], " . $modSettings['gallery_set_images_per_page']
, __FILE__, __LINE__);
$context['picture_list'] = array();
while($row = mysql_fetch_assoc($result))
{
$context['picture_list'][] = $row;
}
mysql_free_result($result);
$context['gallery_stat_title'] = $txt['gallery_stats_toprated'];
$context['page_title'] = $mbname . ' - ' .$txt['gallery_stats_toprated'];
break;
case 'random':
$result = db_query("
SELECT
COUNT(*) as total
FROM {$db_prefix}gallery_pic as p
$wherestats
", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$context['page_index'] = constructPageIndex($scripturl . '?action=gallery;sa=listall;type=' . $_REQUEST['type'] . ';orderby=' . $orderby , $_REQUEST['start'], $row['total'], $modSettings['gallery_set_images_per_page']);
$context['start'] = $_REQUEST['start'];
$result = db_query("
SELECT
p.ID_PICTURE, p.commenttotal, p.totalratings, p.rating, p.filesize,
p.views, p.thumbfilename, p.title, p.ID_MEMBER, m.realName, p.date,
p.description, p.mature, v.ID_PICTURE as unread
FROM {$db_prefix}gallery_pic as p
$wherestats GROUP BY p.ID_PICTURE
ORDER BY RAND() $orderby
LIMIT $context[start], " . $modSettings['gallery_set_images_per_page']
, __FILE__, __LINE__);
$context['picture_list'] = array();
while($row = mysql_fetch_assoc($result))
{
$context['picture_list'][] = $row;
}
mysql_free_result($result);
$context['gallery_stat_title'] = $txt['gallery_main_random'];
$context['page_title'] = $mbname . ' - ' .$txt['gallery_main_random'];
break;
case 'recentcomments':
if (allowedTo('smfgallery_manage'))
{
$wherestats = "
LEFT JOIN {$db_prefix}members AS m ON (m.ID_MEMBER = p.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_log_mark_view AS v ON (p.ID_PICTURE = v.ID_PICTURE AND v.ID_MEMBER = $ID_MEMBER AND v.user_id_cat = p.USER_ID_CAT)
WHERE com.ID_PICTURE = p.ID_PICTURE AND p.approved =1 ";
}
else
$wherestats = "
LEFT JOIN {$db_prefix}members AS m ON (m.ID_MEMBER = p.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_usersettings AS s ON (s.ID_MEMBER = m.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_log_mark_view AS v ON (p.ID_PICTURE = v.ID_PICTURE AND v.ID_MEMBER = $ID_MEMBER AND v.user_id_cat = p.USER_ID_CAT)
LEFT JOIN {$db_prefix}gallery_catperm AS c ON (c.id_group IN ($groupsdata) AND c.id_cat = p.id_cat)
WHERE com.ID_PICTURE = p.ID_PICTURE AND ((s.private =0 || s.private IS NULL ) AND (s.password = '' || s.password IS NULL ) AND p.USER_ID_CAT !=0 AND p.approved =1) || (p.approved = 1 AND p.user_id_cat = 0 AND (c.view IS NULL || c.view = 1)) ";
$result = db_query("
SELECT
COUNT(*) as total
FROM ({$db_prefix}gallery_pic as p, {$db_prefix}gallery_comment as com)
$wherestats AND com.ID_PICTURE = p.ID_PICTURE GROUP BY p.ID_PICTURE
", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$context['page_index'] = constructPageIndex($scripturl . '?action=gallery;sa=listall;type=' . $_REQUEST['type'] . ';orderby=' . $orderby , $_REQUEST['start'], $row['total'], $modSettings['gallery_set_images_per_page']);
$context['start'] = $_REQUEST['start'];
$wherestats = "
LEFT JOIN {$db_prefix}members AS m ON (m.ID_MEMBER = p.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_usersettings AS s ON (s.ID_MEMBER = m.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_log_mark_view AS v ON (p.ID_PICTURE = v.ID_PICTURE AND v.ID_MEMBER = $ID_MEMBER AND v.user_id_cat = p.USER_ID_CAT)
LEFT JOIN {$db_prefix}gallery_catperm AS c ON (c.id_group IN ($groupsdata) AND c.id_cat = p.id_cat)
WHERE (((s.private =0 || s.private IS NULL ) AND (s.password = '' || s.password IS NULL ) AND p.USER_ID_CAT !=0 AND p.approved =1) || (p.approved = 1 AND p.user_id_cat = 0 AND (c.view IS NULL || c.view = 1))) ";
$result = db_query("
SELECT
max(com.ID_COMMENT) AS lastcomment, p.ID_PICTURE, p.commenttotal, p.totalratings, p.rating, p.filesize,
p.views, p.thumbfilename, p.title, p.ID_MEMBER, m.realName, p.date,
p.description, p.mature, v.ID_PICTURE as unread
FROM ({$db_prefix}gallery_pic as p, {$db_prefix}gallery_comment as com)
$wherestats GROUP BY p.ID_PICTURE
ORDER BY lastcomment $orderby
LIMIT $context[start], " . $modSettings['gallery_set_images_per_page']
, __FILE__, __LINE__);
$context['picture_list'] = array();
while($row = mysql_fetch_assoc($result))
{
$context['picture_list'][] = $row;
}
mysql_free_result($result);
$context['gallery_stat_title'] = $txt['gallery_main_recentcomment'];
$context['page_title'] = $mbname . ' - ' . $txt['gallery_main_recentcomment'];
break;
}
}
Logged
spikeweb
Newbie
Offline
Posts: 35
Re: SMF Galllery causing MySQL to hang
«
Reply #8 on:
January 26, 2012, 01:18:17 pm »
Thanks for fix, testing, will let you know
Logged
spikeweb
Newbie
Offline
Posts: 35
Re: SMF Galllery causing MySQL to hang
«
Reply #9 on:
January 30, 2012, 04:48:55 am »
We implemented the fix and the corresponding query does not cause any problem until now.
But,
This one stills causes MySQL to hang :
Query_time: 622 Lock_time: 0 Rows_sent: 20 Rows_examined: 49299284
SELECT
max(com.ID_COMMENT) AS lastcomment, p.ID_PICTURE, p.commenttotal, p.totalratings, p.rating, p.filesize,
p.views, p.thumbfilename, p.title, p.ID_MEMBER, m.realName, p.date,
p.description, p.mature, v.ID_PICTURE as unread
FROM (forum1_gallery_pic as p, forum1_gallery_comment as com)
LEFT JOIN forum1_members AS m ON (m.ID_MEMBER = p.ID_MEMBER)
LEFT JOIN forum1_gallery_usersettings AS s ON (s.ID_MEMBER = m.ID_MEMBER)
LEFT JOIN forum1_gallery_log_mark_view AS v ON (p.ID_PICTURE = v.ID_PICTURE AND v.ID_MEMBER = 0 AND v.user_id_cat = p.USER_ID_CAT)
LEFT JOIN forum1_gallery_catperm AS c ON (c.id_group IN (-1) AND c.id_cat = p.id_cat)
WHERE (((s.private =0 || s.private IS NULL ) AND (s.password = '' || s.password IS NULL ) AND p.USER_ID_CAT !=0 AND p.approved =1) || (p.approved = 1 AND p.user_id_cat = 0 AND (c.view IS NULL || c.view = 1))) GROUP BY p.ID_PICTURE
ORDER BY lastcomment desc
LIMIT 0, 20;
Any new fix ?
Is there any possibility to prevent users not to query the all gallery ?
Logged
SMFHacks
Administrator
Hero Member
Offline
Posts: 9680
Re: SMF Galllery causing MySQL to hang
«
Reply #10 on:
January 30, 2012, 08:29:00 am »
Try this listall function instead this should solve all those problems
Code:
function ListAll()
{
global $db_prefix, $user_info, $context, $txt, $ID_MEMBER, $mbname, $modSettings, $scripturl;
// Is the user allowed to view the gallery?
isAllowedTo('smfgallery_view');
if (!$context['user']['is_guest'])
$groupsdata = implode($user_info['groups'], ',');
else
$groupsdata = -1;
StoreGalleryLocation();
// Show top Tabs
TopButtonTabs();
$type = $_REQUEST['type'];
$context['sub_template'] = 'listall';
$orderby = 'desc';
if (isset($_REQUEST['orderby']))
{
if ($_REQUEST['orderby'] == 'desc')
$orderby = 'desc';
else
$orderby = 'asc';
}
if (allowedTo('smfgallery_manage'))
{
$wherestats = "
LEFT JOIN {$db_prefix}members AS m ON (m.ID_MEMBER = p.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_log_mark_view AS v ON (p.ID_PICTURE = v.ID_PICTURE AND v.ID_MEMBER = $ID_MEMBER AND v.user_id_cat = p.USER_ID_CAT)
WHERE p.approved =1";
}
else
$wherestats = "
LEFT JOIN {$db_prefix}members AS m ON (m.ID_MEMBER = p.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_usersettings AS s ON (s.ID_MEMBER = m.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_log_mark_view AS v ON (p.ID_PICTURE = v.ID_PICTURE AND v.ID_MEMBER = $ID_MEMBER AND v.user_id_cat = p.USER_ID_CAT)
LEFT JOIN {$db_prefix}gallery_catperm AS c ON (c.id_group IN ($groupsdata) AND c.id_cat = p.id_cat)
WHERE ((s.private =0 || s.private IS NULL ) AND (s.password = '' || s.password IS NULL ) AND p.USER_ID_CAT !=0 AND p.approved =1) || (p.approved = 1 AND p.user_id_cat = 0 AND (c.view IS NULL || c.view = 1)) ";
switch ($type)
{
case 'recent':
// Get total number of results
$result = db_query("
SELECT
COUNT(*) as total
FROM {$db_prefix}gallery_pic as p
$wherestats
", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$context['page_index'] = constructPageIndex($scripturl . '?action=gallery;sa=listall;type=' . $_REQUEST['type'] , $_REQUEST['start'], $row['total'], $modSettings['gallery_set_images_per_page']);
$context['start'] = $_REQUEST['start'];
$result = db_query("
SELECT
p.ID_PICTURE, p.commenttotal, p.totalratings, p.rating, p.filesize,
p.views, p.thumbfilename, p.title, p.ID_MEMBER, m.realName, p.date,
p.description, p.mature, v.ID_PICTURE as unread
FROM {$db_prefix}gallery_pic as p
$wherestats GROUP BY p.ID_PICTURE
ORDER BY p.ID_PICTURE $orderby
LIMIT $context[start], " . $modSettings['gallery_set_images_per_page']
, __FILE__, __LINE__);
$context['picture_list'] = array();
while($row = mysql_fetch_assoc($result))
{
$context['picture_list'][] = $row;
}
mysql_free_result($result);
$context['gallery_stat_title'] = $txt['gallery_stats_last'];
$context['page_title'] = $mbname . ' - ' . $txt['gallery_stats_last'];
break;
case 'comments':
// Get total number of results
$result = db_query("
SELECT
COUNT(*) as total
FROM {$db_prefix}gallery_pic as p
$wherestats
", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$context['page_index'] = constructPageIndex($scripturl . '?action=gallery;sa=listall;type=' . $_REQUEST['type'] . ';orderby=' . $orderby , $_REQUEST['start'], $row['total'], $modSettings['gallery_set_images_per_page']);
$context['start'] = $_REQUEST['start'];
$result = db_query("
SELECT
p.ID_PICTURE, p.commenttotal, p.totalratings, p.rating, p.filesize,
p.views, p.thumbfilename, p.title, p.ID_MEMBER, m.realName, p.date,
p.description, p.mature, v.ID_PICTURE as unread
FROM {$db_prefix}gallery_pic as p
$wherestats GROUP BY p.ID_PICTURE
ORDER BY p.commenttotal $orderby
LIMIT $context[start], " . $modSettings['gallery_set_images_per_page']
, __FILE__, __LINE__);
$context['picture_list'] = array();
while($row = mysql_fetch_assoc($result))
{
$context['picture_list'][] = $row;
}
mysql_free_result($result);
$context['gallery_stat_title'] = $txt['gallery_stats_mostcomments'];
$context['page_title'] = $mbname . ' - ' . $txt['gallery_stats_mostcomments'];
break;
case 'views':
// Get total number of results
$result = db_query("
SELECT
COUNT(*) as total
FROM {$db_prefix}gallery_pic as p
$wherestats
", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$context['page_index'] = constructPageIndex($scripturl . '?action=gallery;sa=listall;type=' . $_REQUEST['type'] . ';orderby=' . $orderby , $_REQUEST['start'], $row['total'], $modSettings['gallery_set_images_per_page']);
$context['start'] = $_REQUEST['start'];
$result = db_query("
SELECT
p.ID_PICTURE, p.commenttotal, p.totalratings, p.rating, p.filesize,
p.views, p.thumbfilename, p.title, p.ID_MEMBER, m.realName,
p.date, p.description, p.mature, v.ID_PICTURE as unread
FROM {$db_prefix}gallery_pic as p
$wherestats GROUP BY p.ID_PICTURE
ORDER BY p.views $orderby
LIMIT $context[start], " . $modSettings['gallery_set_images_per_page']
, __FILE__, __LINE__);
$context['picture_list'] = array();
while($row = mysql_fetch_assoc($result))
{
$context['picture_list'][] = $row;
}
mysql_free_result($result);
$context['gallery_stat_title'] = $txt['gallery_stats_viewed'];
$context['page_title'] = $mbname . ' - ' . $txt['gallery_stats_viewed'];
break;
case 'toprated':
$result = db_query("
SELECT
COUNT(*) as total
FROM {$db_prefix}gallery_pic as p
$wherestats
", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$context['page_index'] = constructPageIndex($scripturl . '?action=gallery;sa=listall;type=' . $_REQUEST['type'] . ';orderby=' . $orderby , $_REQUEST['start'], $row['total'], $modSettings['gallery_set_images_per_page']);
$context['start'] = $_REQUEST['start'];
$result = db_query("
SELECT
p.ID_PICTURE, p.commenttotal, p.totalratings, p.rating, p.filesize,
p.views, p.thumbfilename, p.title, p.ID_MEMBER, m.realName, p.date,
p.description, p.mature, v.ID_PICTURE as unread
FROM {$db_prefix}gallery_pic as p
$wherestats GROUP BY p.ID_PICTURE
ORDER BY p.rating $orderby
LIMIT $context[start], " . $modSettings['gallery_set_images_per_page']
, __FILE__, __LINE__);
$context['picture_list'] = array();
while($row = mysql_fetch_assoc($result))
{
$context['picture_list'][] = $row;
}
mysql_free_result($result);
$context['gallery_stat_title'] = $txt['gallery_stats_toprated'];
$context['page_title'] = $mbname . ' - ' .$txt['gallery_stats_toprated'];
break;
case 'random':
$result = db_query("
SELECT
COUNT(*) as total
FROM {$db_prefix}gallery_pic as p
$wherestats
", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$context['page_index'] = constructPageIndex($scripturl . '?action=gallery;sa=listall;type=' . $_REQUEST['type'] . ';orderby=' . $orderby , $_REQUEST['start'], $row['total'], $modSettings['gallery_set_images_per_page']);
$context['start'] = $_REQUEST['start'];
$result = db_query("
SELECT
p.ID_PICTURE, p.commenttotal, p.totalratings, p.rating, p.filesize,
p.views, p.thumbfilename, p.title, p.ID_MEMBER, m.realName, p.date,
p.description, p.mature, v.ID_PICTURE as unread
FROM {$db_prefix}gallery_pic as p
$wherestats GROUP BY p.ID_PICTURE
ORDER BY RAND() $orderby
LIMIT $context[start], " . $modSettings['gallery_set_images_per_page']
, __FILE__, __LINE__);
$context['picture_list'] = array();
while($row = mysql_fetch_assoc($result))
{
$context['picture_list'][] = $row;
}
mysql_free_result($result);
$context['gallery_stat_title'] = $txt['gallery_main_random'];
$context['page_title'] = $mbname . ' - ' .$txt['gallery_main_random'];
break;
case 'recentcomments':
if (allowedTo('smfgallery_manage'))
{
$wherestats = "
LEFT JOIN {$db_prefix}members AS m ON (m.ID_MEMBER = p.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_log_mark_view AS v ON (p.ID_PICTURE = v.ID_PICTURE AND v.ID_MEMBER = $ID_MEMBER AND v.user_id_cat = p.USER_ID_CAT)
WHERE com.ID_PICTURE = p.ID_PICTURE AND p.approved =1 ";
}
else
$wherestats = "
LEFT JOIN {$db_prefix}members AS m ON (m.ID_MEMBER = p.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_usersettings AS s ON (s.ID_MEMBER = m.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_log_mark_view AS v ON (p.ID_PICTURE = v.ID_PICTURE AND v.ID_MEMBER = $ID_MEMBER AND v.user_id_cat = p.USER_ID_CAT)
LEFT JOIN {$db_prefix}gallery_catperm AS c ON (c.id_group IN ($groupsdata) AND c.id_cat = p.id_cat)
WHERE com.ID_PICTURE = p.ID_PICTURE AND ((s.private =0 || s.private IS NULL ) AND (s.password = '' || s.password IS NULL ) AND p.USER_ID_CAT !=0 AND p.approved =1) || (p.approved = 1 AND p.user_id_cat = 0 AND (c.view IS NULL || c.view = 1)) ";
$result = db_query("
SELECT
COUNT(*) as total
FROM ({$db_prefix}gallery_pic as p, {$db_prefix}gallery_comment as com)
$wherestats GROUP BY p.ID_PICTURE
", __FILE__, __LINE__);
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$context['page_index'] = constructPageIndex($scripturl . '?action=gallery;sa=listall;type=' . $_REQUEST['type'] . ';orderby=' . $orderby , $_REQUEST['start'], $row['total'], $modSettings['gallery_set_images_per_page']);
$context['start'] = $_REQUEST['start'];
/*
$wherestats = "
LEFT JOIN {$db_prefix}members AS m ON (m.ID_MEMBER = p.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_usersettings AS s ON (s.ID_MEMBER = m.ID_MEMBER)
LEFT JOIN {$db_prefix}gallery_log_mark_view AS v ON (p.ID_PICTURE = v.ID_PICTURE AND v.ID_MEMBER = $ID_MEMBER AND v.user_id_cat = p.USER_ID_CAT)
LEFT JOIN {$db_prefix}gallery_catperm AS c ON (c.id_group IN ($groupsdata) AND c.id_cat = p.id_cat)
WHERE (((s.private =0 || s.private IS NULL ) AND (s.password = '' || s.password IS NULL ) AND p.USER_ID_CAT !=0 AND p.approved =1) || (p.approved = 1 AND p.user_id_cat = 0 AND (c.view IS NULL || c.view = 1))) ";
*/
$result = db_query("
SELECT
max(com.ID_COMMENT) AS lastcomment, p.ID_PICTURE, p.commenttotal, p.totalratings, p.rating, p.filesize,
p.views, p.thumbfilename, p.title, p.ID_MEMBER, m.realName, p.date,
p.description, p.mature, v.ID_PICTURE as unread
FROM ({$db_prefix}gallery_pic as p, {$db_prefix}gallery_comment as com)
$wherestats GROUP BY p.ID_PICTURE
ORDER BY lastcomment $orderby
LIMIT $context[start], " . $modSettings['gallery_set_images_per_page']
, __FILE__, __LINE__);
$context['picture_list'] = array();
while($row = mysql_fetch_assoc($result))
{
$context['picture_list'][] = $row;
}
mysql_free_result($result);
$context['gallery_stat_title'] = $txt['gallery_main_recentcomment'];
$context['page_title'] = $mbname . ' - ' . $txt['gallery_main_recentcomment'];
break;
}
}
Logged
spikeweb
Newbie
Offline
Posts: 35
Re: SMF Galllery causing MySQL to hang
«
Reply #11 on:
February 06, 2012, 03:44:53 am »
Implemented the fix this morning, test going on and will let you know
Logged
Pages:
[
1
]
« previous
next »
Jump to:
Please select a destination:
-----------------------------
SMFHacks.com
-----------------------------
=> News
=> Site Discussion
===> Suggestions
===> Bugs
-----------------------------
SMF Gallery Pro
-----------------------------
=> Announcements
=> Presales
=> Support
===> Bugs
===> Feature Requests
-----------------------------
SMF Store
-----------------------------
=> Announcements
=> Presales
=> Support
===> Guides and Tips
===> Feature Requests
===> Bugs
-----------------------------
SMF Classifieds
-----------------------------
=> Announcements
=> Presales
=> Support
===> Bugs
===> Feature Requests
-----------------------------
Downloads System Pro
-----------------------------
=> Announcements
=> Presales
=> Support
===> Feature Requests
===> Bugs
-----------------------------
Ad Seller Pro
-----------------------------
=> Presales
=> Support
-----------------------------
Newsletter Pro
-----------------------------
=> Presales
=> Support
===> Feature Requests
-----------------------------
Social Login Pro
-----------------------------
=> Presales
-----------------------------
Badge Awards
-----------------------------
=> Presales
-----------------------------
Tweet Topics/FB Post System
-----------------------------
=> Presales
-----------------------------
SMF Gallery Lite
-----------------------------
=> SMF Gallery Lite
-----------------------------
Modifications/Themes
-----------------------------
=> General SMF Forum
=> Modifications Talk
===> Latest Mods
===> Modification Showcase
=> Theme Talk
===> Theme Showcase
===> Latest Themes
Recent
$txt['downloads_txt_day_l...
by
ApplianceJunk
[
Today
at 10:52:25 am]
Receiving eChecks?
by
ApplianceJunk
[
Today
at 10:35:29 am]
Feature Request: Ban indi...
by
ApplianceJunk
[May 24, 2012, 08:02:50 am]
Custom Fields
by
davejo
[May 24, 2012, 04:11:41 am]
Store IPN AMOUNT CHANGE
by
ApplianceJunk
[May 21, 2012, 08:54:11 am]
Transferring Db data from...
by
~ Phåråoh ~
[May 20, 2012, 11:06:52 am]
SMF vs PhpBB
by
channgam
[May 20, 2012, 05:58:11 am]
Any news?
by
SMFHacks
[May 19, 2012, 06:16:58 pm]
Social Login Pro domain c...
by
SMFHacks
[May 19, 2012, 05:42:37 pm]
licence information and q...
by
SMFHacks
[May 18, 2012, 03:08:38 pm]
Random Picture
Donate to SMFHacks.com
Help Support the SMFHacks.com mod making.
Loading...