diff options
author | Mario Vavti <mario@mariovavti.com> | 2018-02-04 20:42:40 +0100 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2018-02-04 20:42:40 +0100 |
commit | 3cc756f3029e5f3b02008dac94a90e168d398c9a (patch) | |
tree | bc6b6cdc552ef119e0f7beb8b40e83ffe59798c7 /Zotlabs/Module/Network.php | |
parent | 512f3a764361dde44e36fb72c105265d6df298ad (diff) | |
download | volse-hubzilla-3cc756f3029e5f3b02008dac94a90e168d398c9a.tar.gz volse-hubzilla-3cc756f3029e5f3b02008dac94a90e168d398c9a.tar.bz2 volse-hubzilla-3cc756f3029e5f3b02008dac94a90e168d398c9a.zip |
remove some never used indices which prevented our item queries to find the right query execution plan in mysql and adjust some queries to optimze the result
Diffstat (limited to 'Zotlabs/Module/Network.php')
-rw-r--r-- | Zotlabs/Module/Network.php | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/Zotlabs/Module/Network.php b/Zotlabs/Module/Network.php index 551303984..70e0048fb 100644 --- a/Zotlabs/Module/Network.php +++ b/Zotlabs/Module/Network.php @@ -209,8 +209,11 @@ class Network extends \Zotlabs\Web\Controller { : ''); $sql_nets = ''; + + $distinct = ''; + $item_thread_top = ' AND item_thread_top = 1 '; - $sql_extra = " AND item.parent IN ( SELECT parent FROM item WHERE item_thread_top = 1 $sql_options ) "; + $sql_extra = $sql_options; if($group) { $contact_str = ''; @@ -226,7 +229,8 @@ class Network extends \Zotlabs\Web\Controller { $contact_str = ' 0 '; info( t('Privacy group is empty')); } - + $distinct = ' distinct '; + $item_thread_top = ''; $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true $sql_options AND (( author_xchan IN ( $contact_str ) OR owner_xchan in ( $contact_str )) or allow_gid like '" . protect_sprintf('%<' . dbesc($group_hash) . '>%') . "' ) and id = parent $item_normal ) "; $x = group_rec_byhash(local_channel(), $group_hash); @@ -250,6 +254,8 @@ class Network extends \Zotlabs\Web\Controller { intval(local_channel()) ); if($r) { + $distinct = ' distinct '; + $item_thread_top = ''; $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true $sql_options AND uid = " . intval(local_channel()) . " AND ( author_xchan = '" . dbesc($r[0]['abook_xchan']) . "' or owner_xchan = '" . dbesc($r[0]['abook_xchan']) . "' ) $item_normal ) "; $title = replace_macros(get_markup_template("section_title.tpl"),array( '$title' => '<a href="' . zid($r[0]['xchan_url']) . '" ><img src="' . zid($r[0]['xchan_photo_s']) . '" alt="' . urlencode($r[0]['xchan_name']) . '" /></a> <a href="' . zid($r[0]['xchan_url']) . '" >' . $r[0]['xchan_name'] . '</a>' @@ -264,13 +270,15 @@ class Network extends \Zotlabs\Web\Controller { } } elseif($xchan) { - $r = q("select * from xchan where xchan_hash = '%s'", - dbesc($xchan) - ); - if($r) { - $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true $sql_options AND uid = " . intval(local_channel()) . " AND ( author_xchan = '" . dbesc($xchan) . "' or owner_xchan = '" . dbesc($xchan) . "' ) $item_normal ) "; - $title = replace_macros(get_markup_template("section_title.tpl"),array( - '$title' => '<a href="' . zid($r[0]['xchan_url']) . '" ><img src="' . zid($r[0]['xchan_photo_s']) . '" alt="' . urlencode($r[0]['xchan_name']) . '" /></a> <a href="' . zid($r[0]['xchan_url']) . '" >' . $r[0]['xchan_name'] . '</a>' + $r = q("select * from xchan where xchan_hash = '%s'", + dbesc($xchan) + ); + if($r) { + $distinct = ' distinct '; + $item_thread_top = ''; + $sql_extra = " AND item.parent IN ( SELECT DISTINCT parent FROM item WHERE true $sql_options AND uid = " . intval(local_channel()) . " AND ( author_xchan = '" . dbesc($xchan) . "' or owner_xchan = '" . dbesc($xchan) . "' ) $item_normal ) "; + $title = replace_macros(get_markup_template("section_title.tpl"),array( + '$title' => '<a href="' . zid($r[0]['xchan_url']) . '" ><img src="' . zid($r[0]['xchan_photo_s']) . '" alt="' . urlencode($r[0]['xchan_name']) . '" /></a> <a href="' . zid($r[0]['xchan_url']) . '" >' . $r[0]['xchan_name'] . '</a>' )); $o = $tabs; $o .= $title; @@ -373,6 +381,8 @@ class Network extends \Zotlabs\Web\Controller { } if($conv) { + $distinct = ' distinct '; + $item_thread_top = ''; $sql_extra .= sprintf(" AND parent IN (SELECT distinct(parent) from item where ( author_xchan like '%s' or item_mentionsme = 1 )) ", dbesc(protect_sprintf($channel['channel_hash'])) ); @@ -448,7 +458,7 @@ class Network extends \Zotlabs\Web\Controller { if($nouveau && $load) { // "New Item View" - show all items unthreaded in reverse created date order - $items = q("SELECT item.*, item.id AS item_id, received FROM item + $items = q("SELECT item.*, item.id AS item_id, received FROM item left join abook on ( item.owner_xchan = abook.abook_xchan $abook_uids ) $net_query WHERE true $uids $item_normal @@ -477,11 +487,11 @@ class Network extends \Zotlabs\Web\Controller { if($load) { // Fetch a page full of parent items for this page - $r = q("SELECT distinct item.id AS item_id, $ordering FROM item + $r = q("SELECT $distinct item.parent AS item_id FROM item left join abook on ( item.owner_xchan = abook.abook_xchan $abook_uids ) $net_query - WHERE true $uids $item_normal - AND item.parent = item.id + WHERE true $uids $item_thread_top $item_normal + AND item.mid = item.parent_mid and (abook.abook_blocked = 0 or abook.abook_flags is null) $sql_extra3 $sql_extra $sql_nets $net_query2 |