diff options
author | Mario <mario@mariovavti.com> | 2023-09-10 19:09:55 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2023-09-10 19:09:55 +0000 |
commit | 75e75b93cff5b2fb5d6243a908ee003b3faf010a (patch) | |
tree | 6169ce5d7e0857f6ecb32275672c9e7238864700 /Zotlabs | |
parent | 0e8ecbc9fc108b4903eb013ca0a4a1f4beb5fbe1 (diff) | |
download | volse-hubzilla-75e75b93cff5b2fb5d6243a908ee003b3faf010a.tar.gz volse-hubzilla-75e75b93cff5b2fb5d6243a908ee003b3faf010a.tar.bz2 volse-hubzilla-75e75b93cff5b2fb5d6243a908ee003b3faf010a.zip |
an attempt to cache seen item mids for the purpose that we can hide seen pubstream items from the notifications - might revert if it turns out that it does not scale
Diffstat (limited to 'Zotlabs')
-rw-r--r-- | Zotlabs/Lib/Cache.php | 14 | ||||
-rw-r--r-- | Zotlabs/Module/Pubstream.php | 3 | ||||
-rw-r--r-- | Zotlabs/Module/Sse_bs.php | 40 | ||||
-rw-r--r-- | Zotlabs/Widget/Notifications.php | 2 |
4 files changed, 42 insertions, 17 deletions
diff --git a/Zotlabs/Lib/Cache.php b/Zotlabs/Lib/Cache.php index a5052a183..60bf64611 100644 --- a/Zotlabs/Lib/Cache.php +++ b/Zotlabs/Lib/Cache.php @@ -5,17 +5,17 @@ namespace Zotlabs\Lib; /** * cache api */ - + class Cache { - + /** * @brief Returns cached content - * + * * @param string $key * @param string $age in SQL format, default is '30 DAY' * @return string */ - + public static function get($key, $age = '') { $hash = hash('whirlpool',$key); @@ -25,12 +25,12 @@ class Cache { db_utcnow(), db_quoteinterval(($age ? $age : get_config('system','object_cache_days', '30') . ' DAY')) ); - + if ($r) return $r[0]['v']; return null; } - + public static function set($key,$value) { $hash = hash('whirlpool',$key); @@ -45,7 +45,7 @@ class Cache { dbesc($hash)); } else { - q("INSERT INTO cache ( k, v, updated) VALUES ('%s','%s','%s')", + q("INSERT INTO cache (k, v, updated) VALUES ('%s', '%s', '%s')", dbesc($hash), dbesc($value), dbesc(datetime_convert())); diff --git a/Zotlabs/Module/Pubstream.php b/Zotlabs/Module/Pubstream.php index 4bd1faeff..4b1cd6afb 100644 --- a/Zotlabs/Module/Pubstream.php +++ b/Zotlabs/Module/Pubstream.php @@ -99,9 +99,6 @@ class Pubstream extends \Zotlabs\Web\Controller { nav_set_selected(t('Public Stream')); - if(!$mid) - $_SESSION['static_loadtime'] = datetime_convert(); - $maxheight = get_config('system','home_divmore_height'); if(! $maxheight) $maxheight = 400; diff --git a/Zotlabs/Module/Sse_bs.php b/Zotlabs/Module/Sse_bs.php index fdaab4ab8..78adf1859 100644 --- a/Zotlabs/Module/Sse_bs.php +++ b/Zotlabs/Module/Sse_bs.php @@ -7,6 +7,7 @@ use Zotlabs\Lib\Apps; use Zotlabs\Web\Controller; use Zotlabs\Lib\Enotify; use Zotlabs\Lib\XConfig; +use Zotlabs\Lib\Cache; class Sse_bs extends Controller { @@ -117,14 +118,29 @@ class Sse_bs extends Controller { function mark_read($arr) { - if(! self::$uid) - return; - $mids = []; $str = ''; + $mids_all_json = Cache::get('sse_mids_all_' . session_id()); + + if (!$mids_all_json) + $mids_all_json = '[]'; + + $mids_all = json_decode($mids_all_json, true); + foreach($arr as $a) { - $mids[] = '\'' . dbesc(unpack_link_id($a)) . '\''; + $mid_str = '\'' . dbesc(unpack_link_id($a)) . '\''; + $mids[] = $mid_str; + + if (!in_array($mid_str, $mids_all)) { + $mids_all[] = $mid_str; + } + } + + Cache::set('sse_mids_all_' . session_id(), json_encode($mids_all)); + + if(! self::$uid) { + return; } $str = implode(',', $mids); @@ -411,8 +427,9 @@ class Sse_bs extends Controller { } } - if(! isset($_SESSION['static_loadtime'])) + if(!isset($_SESSION['static_loadtime'])) { $_SESSION['static_loadtime'] = datetime_convert(); + } $limit = intval(self::$limit); $offset = self::$offset; @@ -430,6 +447,13 @@ class Sse_bs extends Controller { if(self::$xchans) $sql_extra2 = " AND CASE WHEN verb = '" . ACTIVITY_SHARE . "' THEN owner_xchan ELSE author_xchan END IN (" . self::$xchans . ") "; + $sql_extra3 = ''; + $sse_mids_all_json = Cache::get('sse_mids_all_' . session_id()); + if ($sse_mids_all_json) { + $sse_mids_all = json_decode($sse_mids_all_json, true); + $sql_extra3 = " AND mid NOT IN (" . protect_sprintf(implode(',', $sse_mids_all)) . ") "; + } + $uids = " AND uid IN ( " . $sys['channel_id'] . " ) "; $site_firehose = get_config('system', 'site_firehose', 0); @@ -452,10 +476,11 @@ class Sse_bs extends Controller { $item_normal $sql_extra $sql_extra2 + $sql_extra3 ORDER BY created DESC LIMIT $limit OFFSET $offset", dbescdate($_SESSION['sse_loadtime']), dbesc(self::$ob_hash), - dbescdate($_SESSION['static_loadtime']) + dbescdate($_SESSION['last_login_date'] ?? $_SESSION['static_loadtime']) ); if($items) { @@ -478,8 +503,9 @@ class Sse_bs extends Controller { AND created > '%s' $item_normal $sql_extra + $sql_extra3 AND author_xchan != '%s' LIMIT 100", - dbescdate($_SESSION['static_loadtime']), + dbescdate($_SESSION['last_login_date'] ?? $_SESSION['static_loadtime']), dbesc(self::$ob_hash) ); diff --git a/Zotlabs/Widget/Notifications.php b/Zotlabs/Widget/Notifications.php index a4e632a9f..b16303be6 100644 --- a/Zotlabs/Widget/Notifications.php +++ b/Zotlabs/Widget/Notifications.php @@ -157,9 +157,11 @@ class Notifications { 'url' => 'pubstream', 'label' => t('Public stream') ], + /* 'markall' => [ 'label' => t('Mark all notifications seen') ], + */ 'filter' => [ 'posts_label' => t('Show new posts only'), 'name_label' => t('Filter by name or address') |