Facebook  Twitter 

SMFHacks.com

+-

SMFHacks.com

+- User Information

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

+- Forum Stats

Members
Total Members: 4257
Latest: Alex998.
New This Month: 1
New This Week: 0
New Today: 0
Stats
Total Posts: 43295
Total Topics: 7523
Most Online Today: 230
Most Online Ever: 2482
(April 09, 2011, 07:02:45 pm)
Users Online
Members: 0
Guests: 248
Total: 248

Author Topic: SMF Galllery causing MySQL to hang  (Read 9897 times)

0 Members and 1 Guest are viewing this topic.

Offline spikeweb

  • Member
  • *
  • Posts: 38
    • View Profile
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,

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16452
    • View Profile
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: [Select]
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;
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline spikeweb

  • Member
  • *
  • Posts: 38
    • View Profile
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    

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16452
    • View Profile
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.
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline spikeweb

  • Member
  • *
  • Posts: 38
    • View Profile
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 ...

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16452
    • View Profile
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.
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline spikeweb

  • Member
  • *
  • Posts: 38
    • View Profile
Re: SMF Galllery causing MySQL to hang
« Reply #6 on: January 26, 2012, 12:45:34 am »
SMF is 1.1.16  ;)

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16452
    • View Profile
Re: SMF Galllery causing MySQL to hang
« Reply #7 on: January 26, 2012, 09:10:35 am »
Open Sources/Gallery.php
Find
Code: [Select]
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: [Select]
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;


}


}
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline spikeweb

  • Member
  • *
  • Posts: 38
    • View Profile
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 ;)

Offline spikeweb

  • Member
  • *
  • Posts: 38
    • View Profile
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 ?

Offline SMFHacks

  • Administrator
  • Hero Member
  • *****
  • Posts: 16452
    • View Profile
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: [Select]

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;


}


}
Get your Forum Ranked! at https://www.forumrankings.net - find out how your forum compares with others!

Like What I do? Support me at https://www.patreon.com/vbgamer45/

Offline spikeweb

  • Member
  • *
  • Posts: 38
    • View Profile
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 ;)

 

Related Topics

  Subject / Started by Replies Last post
1 Replies
5010 Views
Last post September 12, 2007, 10:45:56 am
by propyl
1 Replies
4131 Views
Last post December 16, 2007, 07:09:16 pm
by SMFHacks
0 Replies
3098 Views
Last post December 16, 2007, 07:09:27 pm
by SMFHacks
1 Replies
4055 Views
Last post January 31, 2008, 05:28:27 pm
by SMFHacks
12 Replies
2419 Views
Last post December 27, 2020, 12:56:07 pm
by SMFHacks

+- Recent Topics

Please Help! by SMFHacks
April 17, 2024, 08:04:55 am

Rate own images by fvlog19
April 11, 2024, 10:56:53 am

Tidy Child Boards on 2.1.4 by SMFHacks
April 04, 2024, 03:54:12 pm

Problems SMF 2.0.19 > 2.1.4 SMF Gallery Pro - Recents Images to overall header by Michel68
March 30, 2024, 12:41:08 pm

Can't DROP 'id_member'; check that column/key exists Datei: by SMFHacks
March 30, 2024, 11:58:20 am

No thumbnails on new uploads by Tonyvic
March 29, 2024, 06:26:18 am

Display the Contact Page for guests by SMFHacks
March 27, 2024, 10:55:43 am

is it possible to add support for odysee.com by fvlog19
March 21, 2024, 08:47:51 am

Request for admin notification by davejo
March 10, 2024, 01:31:59 am

I need help with torrent upload by Ineedsmfhelp
March 09, 2024, 10:01:13 pm

Powered by EzPortal