diff options
author | Mario <mario@mariovavti.com> | 2020-10-25 11:28:41 +0100 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2020-10-25 11:28:41 +0100 |
commit | 35299ed7c36e7adbc93b8f43076c07fb824c4db5 (patch) | |
tree | 2343096b505c34464afd9a7e72c24370aab307e1 /include | |
parent | 6979ea44f44dd665c05281660aefa6bbb0fab005 (diff) | |
parent | 7008cf326903ea6f1887011fca1e5fa8ca626d28 (diff) | |
download | volse-hubzilla-35299ed7c36e7adbc93b8f43076c07fb824c4db5.tar.gz volse-hubzilla-35299ed7c36e7adbc93b8f43076c07fb824c4db5.tar.bz2 volse-hubzilla-35299ed7c36e7adbc93b8f43076c07fb824c4db5.zip |
Merge branch 'dev' into 'dev'
Add results caching on public tag and profile categories fetching
See merge request hubzilla/core!1875
Diffstat (limited to 'include')
-rw-r--r-- | include/contact_widgets.php | 49 | ||||
-rw-r--r-- | include/taxonomy.php | 93 |
2 files changed, 82 insertions, 60 deletions
diff --git a/include/contact_widgets.php b/include/contact_widgets.php index 6ad276b00..626a825b2 100644 --- a/include/contact_widgets.php +++ b/include/contact_widgets.php @@ -1,6 +1,6 @@ <?php /** @file */ - +use Zotlabs\Lib\Cache; function findpeople_widget() { @@ -59,6 +59,7 @@ function fileas_widget($baseurl,$selected = '') { )); } + function categories_widget($baseurl,$selected = '') { if(! feature_enabled(App::$profile['profile_uid'],'categories')) @@ -70,25 +71,36 @@ function categories_widget($baseurl,$selected = '') { $item_normal = item_normal(); + $key = __FUNCTION__ . "-" . App::$profile['profile_uid']; + $content = Cache::get($key, '5 MINUTE'); + + if (! $content) { + $r = q("select distinct(term.term) from term join item on term.oid = item.id + where item.uid = %d + and term.uid = item.uid + and term.ttype = %d + and term.otype = %d + and item.owner_xchan = '%s' + and item.item_wall = 1 + and item.verb != '%s' + $item_normal + $sql_extra + order by term.term asc", + intval(App::$profile['profile_uid']), + intval(TERM_CATEGORY), + intval(TERM_OBJ_POST), + dbesc(App::$profile['channel_hash']), + dbesc(ACTIVITY_UPDATE) + ); + } + else + $r = unserialize($content); + $terms = array(); - $r = q("select distinct(term.term) from term join item on term.oid = item.id - where item.uid = %d - and term.uid = item.uid - and term.ttype = %d - and term.otype = %d - and item.owner_xchan = '%s' - and item.item_wall = 1 - and item.verb != '%s' - $item_normal - $sql_extra - order by term.term asc", - intval(App::$profile['profile_uid']), - intval(TERM_CATEGORY), - intval(TERM_OBJ_POST), - dbesc(App::$profile['channel_hash']), - dbesc(ACTIVITY_UPDATE) - ); if($r && count($r)) { + + Cache::set($key, serialize($r)); + foreach($r as $rr) $terms[] = array('name' => $rr['term'], 'selected' => (($selected == $rr['term']) ? 'selected' : '')); @@ -104,6 +116,7 @@ function categories_widget($baseurl,$selected = '') { return ''; } + function cardcategories_widget($baseurl,$selected = '') { if(! feature_enabled(App::$profile['profile_uid'],'categories')) diff --git a/include/taxonomy.php b/include/taxonomy.php index b0304de5b..e06568d19 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -5,6 +5,9 @@ // and save to file categories in square brackets. // To do this we need to escape these characters if they appear in our tag. +use Zotlabs\Lib\Cache; + + function file_tag_encode($s) { return str_replace(array('<','>','[',']'),array('%3c','%3e','%5b','%5d'),$s); } @@ -327,50 +330,56 @@ function pubtagblock($net,$site,$limit,$recent = 0,$safemode = 1, $type = TERM_H return $o; } -function pub_tagadelic($net,$site,$limit,$recent,$safemode,$type) { - - - $item_normal = item_normal(); - $count = intval($limit); - - if($site) { - $uids = " and item.uid in ( " . stream_perms_api_uids(PERMS_PUBLIC) . " ) and item_private = 0 and item_wall = 1 "; - } - else { - $sys = get_sys_channel(); - $uids = " and item.uid = " . intval($sys['channel_id']) . " "; - $sql_extra = " and item_private = 0 "; - } - - if($recent) - $sql_extra .= " and item.created > '" . datetime_convert('UTC','UTC', 'now - ' . intval($recent) . ' days ') . "' "; +function pub_tagadelic($net,$site,$limit,$recent,$safemode,$type) { - if($safemode) { - $unsafetags = get_config('system','unsafepubtags', [ 'boobs', 'bot', 'rss', 'girl','girls', 'nsfw', 'sexy', 'nude' ]); - if($unsafetags) { - $sql_extra .= " and not term.term in ( " . stringify_array($unsafetags,true) . ") "; - } - } - - - // Fetch tags - $r = q("select term, count(term) as total from term left join item on term.oid = item.id - where term.ttype = %d - and otype = %d and item_type = %d - $sql_extra $uids $item_normal - group by term order by total desc %s", - intval($type), - intval(TERM_OBJ_POST), - intval(ITEM_TYPE_POST), - ((intval($count)) ? "limit $count" : '') - ); - - if(! $r) - return array(); - - return Zotlabs\Text\Tagadelic::calc($r); - + $item_normal = item_normal(); + $count = intval($limit); + + if($site) + $uids = " and item.uid in ( " . stream_perms_api_uids(PERMS_PUBLIC) . " ) and item_private = 0 and item_wall = 1 "; + else { + $sys = get_sys_channel(); + $uids = " and item.uid = " . intval($sys['channel_id']) . " "; + $sql_extra = " and item_private = 0 "; + } + + if($recent) + $sql_extra .= " and item.created > '" . datetime_convert('UTC','UTC', 'now - ' . intval($recent) . ' days ') . "' "; + + + if($safemode) { + $unsafetags = get_config('system','unsafepubtags', [ 'boobs', 'bot', 'rss', 'girl','girls', 'nsfw', 'sexy', 'nude' ]); + if($unsafetags) { + $sql_extra .= " and not term.term in ( " . stringify_array($unsafetags,true) . ") "; + } + } + + + $key = __FUNCTION__ . "-" . md5($site . $recent . $safemode . $limit . $type); + $content = Cache::get($key, '1 MINUTE'); + + if(! $content) { + // Fetch tags + $r = q("SELECT term, count(term) AS total FROM term LEFT JOIN item ON term.oid = item.id + where term.ttype = %d + and otype = %d and item_type = %d + $sql_extra $uids $item_normal + group by term order by total desc %s", + intval($type), + intval(TERM_OBJ_POST), + intval(ITEM_TYPE_POST), + ((intval($count)) ? "limit $count" : '') + ); + } else + $r = unserialize($content); + + if(! $r) + return array(); + else + Cache::set($key, serialize($r)); + + return Zotlabs\Text\Tagadelic::calc($r); } |