From 3836e75c89573baca6b029a5fd36401696b86e8d Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Thu, 21 Jan 2021 09:08:53 +0100 Subject: Implement SQL query background caching --- Zotlabs/Daemon/Cache_query.php | 34 ++++++++++++++++++++++++++++ Zotlabs/Daemon/Expire.php | 8 +++---- include/contact_widgets.php | 38 ++++++++++++++++++-------------- include/taxonomy.php | 50 ++++++++++++++++++++++-------------------- 4 files changed, 85 insertions(+), 45 deletions(-) create mode 100644 Zotlabs/Daemon/Cache_query.php diff --git a/Zotlabs/Daemon/Cache_query.php b/Zotlabs/Daemon/Cache_query.php new file mode 100644 index 000000000..18d19cdf2 --- /dev/null +++ b/Zotlabs/Daemon/Cache_query.php @@ -0,0 +1,34 @@ + $rr['term'], 'selected' => (($selected == $rr['term']) ? 'selected' : '')); diff --git a/include/taxonomy.php b/include/taxonomy.php index e06568d19..5681db88c 100644 --- a/include/taxonomy.php +++ b/include/taxonomy.php @@ -354,30 +354,32 @@ function pub_tagadelic($net,$site,$limit,$recent,$safemode,$type) { $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)); + + $key = __FUNCTION__ . "-" . md5($site . $recent . $safemode . $limit . $type); + + $content = Cache::get($key, '1 MINUTE'); + if(! $content) { + + $content = Cache::get($key, '1 WEEK'); + $arr = [ + "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" : '') + ]; + + \Zotlabs\Daemon\Master::Summon([ 'Cache_query', $key, $arr ]); + } + + $r = unserialize($content); + if(! $r) + return []; return Zotlabs\Text\Tagadelic::calc($r); } -- cgit v1.2.3