IPB php function works but is slow. SQL needs to be faster -


i'm using small part of function wanted post provide big picture. there part of query in function finds recent attachments user has posted forums. block on user profile. works problem ... it's slow!! core attachments locks 30+ seconds , makes site unusable.

any 1 appreciated.

   private function getattimages($limit, $forumids = 0, $fidsreverse = false, $topicids = 0, $membersids = 0, $order = 'attach_date', $sort = 'desc', $group = null)         {             $fids = '';              if ($forumids)             {                 $r = '';                 if ($fidsreverse)                 {                     $r = ' not ';                 }                  if (is_array($forumids))                 {                     $forumids = implode(',', $forumids);                 }                  $fids = ' , forums_topics.forum_id ' . $r . ' in (' . $forumids .  ')';             }              $tids = '';             if ($topicids)             {                 $tids = ' , forums_topics.tid in (' . $topicids . ')';             }              $mids = '';             if ($membersids)             {                 $mids = ' , core_attachments.attach_member_id in (' . $membersids . ')';             }               $wheret = array();             $joinst = array();              $findinposts = ' , ' . \ips\db::i()->findinset('queued', array('0'));             $joinst[] = array(                                 'select'    => 'forums_posts.*',                                 'from'      => 'forums_posts',                                 'where'     => array("forums_posts.pid=core_attachments_map.id2" . $findinposts),                         );              $findintopics = ' , ' . \ips\db::i()->findinset('approved', array('1'));             $joinst[] = array(                                 'select'    => 'forums_topics.*',                                 'from'      => 'forums_topics',                                 'where'     => array("forums_topics.tid=forums_posts.topic_id" . $findintopics . $fids . $tids),                         );              $select = 'core_attachments.attach_id custom_data, core_attachments.*';             if ($group)             {                 $select = 'core_attachments.attach_id custom_data, count(attach_is_image) cnt_images, sum(attach_hits) summ_attach_hits, core_attachments.*';             }              $joinst[] = array(                                 'select'    => $select,                                 'from'      => 'core_attachments',                                 'where'     => array('core_attachments.attach_is_image=1 , core_attachments.attach_is_archived=0 , core_attachments.attach_id=core_attachments_map.attachment_id' . $mids),                         );                            $joinst[] = array(  'select'    => 'core_members.member_id, core_members.member_group_id, core_members.mgroup_others, core_members.name, core_members.members_seo_name',                                 'from'      => 'core_members',                                 'where'     => array('core_attachments.attach_member_id=core_members.member_id' . $mids),                         );              $joinst[] = array(  'select'    => 'core_permission_index.perm_id',                                 'from'      => 'core_permission_index',                                 'where'     => array("core_permission_index.app='forums' , core_permission_index.perm_type='forum' , core_permission_index.perm_type_id=forums_topics.forum_id"),                         );              $groupt = $group;              $wheret[] = array(                 "core_attachments_map.location_key='forums_forums' , " .                  \ips\db::i()->findinset('perm_view', array_merge(array(\ips\member::loggedin()->member_group_id), array_filter(explode(',', \ips\member::loggedin()->mgroup_others)))) . " or perm_view='*'" .                 $fids . $tids . $mids             );              $table = new \ips\helpers\table\db(                 'core_attachments_map',                 \ips\http\url::internal('app=core&module=system&controller=nbattachpictures', 'front', 'nbattachpictures'),                 $wheret,                 $groupt             );              $table->joins = $joinst;             $table->limit = $limit;             $table->sortby = $order;             $table->sortdirection = $sort;              $table->rowstemplate = array(\ips\theme::i()->gettemplate('plugins', 'core', 'global'), 'nbattachmentsblocksrows');              $table->parsers = array(                 'custom_data' => function( $val, $row )                 {                     return array(                         'topic_data' => \ips\http\url::internal("app=forums&module=forums&controller=topic&id={$row['tid']}", 'front', 'forums_topic', array($row['title_seo'])),                         'summ_attach_hits' => $row['summ_attach_hits'],                         'jewel' => $this->attachjewel($row['summ_attach_hits']),                     );                 },             );              return $table;         } 


Comments