From 08c2c9bc22b5cffc21e8f7d7ea1cda30c2e1af93 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 15 Nov 2022 19:29:29 +0000 Subject: possible fix for issue #1698 --- Zotlabs/Module/Follow.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Follow.php b/Zotlabs/Module/Follow.php index 54e29c492..f8bfc11f3 100644 --- a/Zotlabs/Module/Follow.php +++ b/Zotlabs/Module/Follow.php @@ -70,12 +70,12 @@ class Follow extends Controller { } $uid = local_channel(); - $url = notags(trim(punify($_REQUEST['url']))); + $url = notags(punify(trim($_REQUEST['url']))); $return_url = $_SESSION['return_url']; $interactive = $_REQUEST['interactive'] ?? 1; $channel = App::get_channel(); - $result = Connect::connect($channel,$url); + $result = Connect::connect($channel, $url); if ($result['success'] == false) { if ($result['message']) { -- cgit v1.2.3 From c392a77b46958555bc16592fe4d57e9ab0b7e126 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 15 Nov 2022 21:22:10 +0000 Subject: performance: just count the first 99 unseen items and display 99+ if there are more than 99 --- Zotlabs/Module/Sse_bs.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Sse_bs.php b/Zotlabs/Module/Sse_bs.php index 3a4e4e09e..4aabcafcb 100644 --- a/Zotlabs/Module/Sse_bs.php +++ b/Zotlabs/Module/Sse_bs.php @@ -205,18 +205,18 @@ class Sse_bs extends Controller { } - $r = q("SELECT count(id) as total FROM item + $r = q("SELECT id FROM item WHERE uid = %d and item_unseen = 1 AND item_wall = 0 AND item_private IN (0, 1) AND obj_type NOT IN ('Document', 'Video', 'Audio', 'Image') AND author_xchan != '%s' $item_normal - $sql_extra", + $sql_extra LIMIT 100", intval(self::$uid), dbesc(self::$ob_hash) ); if($r) - $result['network']['count'] = intval($r[0]['total']); + $result['network']['count'] = count($r); return $result; } @@ -285,17 +285,17 @@ class Sse_bs extends Controller { } - $r = q("SELECT count(id) as total FROM item + $r = q("SELECT id FROM item WHERE uid = %d and item_unseen = 1 AND item_private = 2 $item_normal $sql_extra - AND author_xchan != '%s'", + AND author_xchan != '%s' LIMIT 100", intval(self::$uid), dbesc(self::$ob_hash) ); if($r) - $result['dm']['count'] = intval($r[0]['total']); + $result['dm']['count'] = count($r); return $result; } @@ -365,17 +365,17 @@ class Sse_bs extends Controller { } - $r = q("SELECT count(id) as total FROM item + $r = q("SELECT id FROM item WHERE uid = %d and item_unseen = 1 AND item_wall = 1 AND item_private IN (0, 1) $item_normal $sql_extra - AND author_xchan != '%s'", + AND author_xchan != '%s' LIMIT 100", intval(self::$uid), dbesc(self::$ob_hash) ); if($r) - $result['home']['count'] = intval($r[0]['total']); + $result['home']['count'] = count($r); return $result; } @@ -458,19 +458,19 @@ class Sse_bs extends Controller { } - $r = q("SELECT count(id) as total FROM item + $r = q("SELECT id FROM item WHERE uid = %d AND item_unseen = 1 AND created > '%s' $item_normal $sql_extra - AND author_xchan != '%s'", + AND author_xchan != '%s' LIMIT 100", intval($sys['channel_id']), dbescdate($_SESSION['static_loadtime']), dbesc(self::$ob_hash) ); if($r) - $result['pubs']['count'] = intval($r[0]['total']); + $result['pubs']['count'] = count($r); return $result; } -- cgit v1.2.3 From 5216c5b23213b1a97051fe7150086109c8a00df1 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 17 Nov 2022 08:57:09 +0000 Subject: fix regression when adding feed contacts --- Zotlabs/Lib/Connect.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/Connect.php b/Zotlabs/Lib/Connect.php index 4570627fc..802bbe0f5 100644 --- a/Zotlabs/Lib/Connect.php +++ b/Zotlabs/Lib/Connect.php @@ -109,10 +109,12 @@ class Connect { if ($wf || $d) { + $xchan_hash = (($wf) ? $wf : $url); + // something was discovered - find the record which was just created. $r = q("select * from xchan where ( xchan_hash = '%s' or xchan_url = '%s' or xchan_addr = '%s' ) $sql_options", - dbesc($wf ?? $url), + dbesc($xchan_hash), dbesc($url), dbesc($url) ); -- cgit v1.2.3 From 805074a0f926dbe63e44241a1fb965188cb47908 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 17 Nov 2022 09:09:02 +0000 Subject: externals: fix warnings --- Zotlabs/Daemon/Externals.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Externals.php b/Zotlabs/Daemon/Externals.php index 5b7954c2f..91fa09044 100644 --- a/Zotlabs/Daemon/Externals.php +++ b/Zotlabs/Daemon/Externals.php @@ -19,6 +19,7 @@ class Externals { $importer = get_sys_channel(); $total = 0; $attempts = 0; + $url = ''; logger('externals: startup', LOGGER_DEBUG); @@ -67,9 +68,8 @@ class Externals { datetime_convert('UTC', 'UTC', 'now - 30 days') ); - $contact = $r[0]; - - if ($contact) { + if ($r) { + $contact = $r[0]; $url = $contact['hubloc_id_url']; } } -- cgit v1.2.3 From 0e157e4e8b480b4a848a05e73aa11dfcd54dfd9b Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 17 Nov 2022 09:11:34 +0000 Subject: remove logging --- Zotlabs/Lib/Libsync.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php index 09b81dc83..fd9886f71 100644 --- a/Zotlabs/Lib/Libsync.php +++ b/Zotlabs/Lib/Libsync.php @@ -184,8 +184,6 @@ class Libsync { require_once('include/import.php'); -hz_syslog(print_r($arr, true)); - $result = []; $keychange = ((array_key_exists('keychange', $arr)) ? true : false); -- cgit v1.2.3 From 0e6b27c9f46141c3ca92fc8dddc51d866cf5f3c9 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 17 Nov 2022 11:50:13 +0000 Subject: if a feed fails, do not update connected timestamp. attempt to poll feeds only once a day if we could not fetch it last time we tried --- Zotlabs/Daemon/Onepoll.php | 13 +++++++++++-- Zotlabs/Daemon/Poller.php | 7 +++++++ 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Onepoll.php b/Zotlabs/Daemon/Onepoll.php index f2b5d8c58..0a30a0c7d 100644 --- a/Zotlabs/Daemon/Onepoll.php +++ b/Zotlabs/Daemon/Onepoll.php @@ -64,12 +64,21 @@ class Onepoll { if ($contact['xchan_network'] === 'rss') { logger('onepoll: processing feed ' . $contact['xchan_name'], LOGGER_DEBUG); $alive = handle_feed($importer['channel_id'], $contact_id, $contact['xchan_hash']); - if ($alive) { - q("update abook set abook_connected = '%s' where abook_id = %d", + + if (!$alive) { + q("update abook set abook_updated = '%s' where abook_id = %d", dbesc(datetime_convert()), intval($contact['abook_id']) ); + return; } + + q("update abook set abook_updated = '%s', abook_connected = '%s' where abook_id = %d", + dbesc(datetime_convert()), + dbesc(datetime_convert()), + intval($contact['abook_id']) + ); + return; } diff --git a/Zotlabs/Daemon/Poller.php b/Zotlabs/Daemon/Poller.php index 88213a7c9..702c940a3 100644 --- a/Zotlabs/Daemon/Poller.php +++ b/Zotlabs/Daemon/Poller.php @@ -93,7 +93,14 @@ class Poller { $min = intval(get_config('system', 'minimum_feedcheck_minutes')); if (!$min) $min = 60; + + if ($t !== $c) { + // if the last fetch failed only attempt fetch once a day + $min = 60 * 24; + } + $x = datetime_convert('UTC', 'UTC', "now - $min minutes"); + if ($c < $x) { Master::Summon(['Onepoll', $contact['abook_id']]); if ($interval) -- cgit v1.2.3 From 59e6989cbcc90ae13eb175e4f1730a9c9d4fc6cd Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 18 Nov 2022 10:43:33 +0000 Subject: hq widget: implement thread unseen items count --- Zotlabs/Widget/Messages.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Widget/Messages.php b/Zotlabs/Widget/Messages.php index 38c822502..199bd8665 100644 --- a/Zotlabs/Widget/Messages.php +++ b/Zotlabs/Widget/Messages.php @@ -34,7 +34,8 @@ class Messages { 'starred_messages_title' => t('Starred messages'), 'notice_messages_title' => t('Notices'), 'loading' => t('Loading'), - 'empty' => t('No messages') + 'empty' => t('No messages'), + 'unseen' => t('Unseen') ] ]); @@ -147,14 +148,23 @@ class Messages { $icon = ''; } + $unseen = q("SELECT count(id) AS total FROM item WHERE uid = %d + AND parent = %d + AND item_thread_top = 0 + AND item_unseen = 1", + intval(local_channel()), + intval($item['id']) + ); + $entries[$i]['author_name'] = $item['author']['xchan_name']; - $entries[$i]['author_addr'] = $item['author']['xchan_addr'] ?? $item['author']['xchan_url']; + $entries[$i]['author_addr'] = (($item['author']['xchan_addr']) ? $item['author']['xchan_addr'] : $item['author']['xchan_url']); $entries[$i]['info'] = $info; $entries[$i]['created'] = datetime_convert('UTC', date_default_timezone_get(), $item['created']); $entries[$i]['summary'] = $summary; $entries[$i]['b64mid'] = gen_link_id($item['mid']); $entries[$i]['href'] = z_root() . '/hq/' . gen_link_id($item['mid']); $entries[$i]['icon'] = $icon; + $entries[$i]['unseen'] = (($unseen[0]['total']) ? $unseen[0]['total'] : (($item['item_unseen']) ? ' ' : '')); $i++; } -- cgit v1.2.3 From bf335ecaf36e628fc76b3fc84c4a73ab82f9e2a0 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 18 Nov 2022 13:32:14 +0000 Subject: hq widget: use distinct classes for seen and unseen thread items count --- Zotlabs/Widget/Messages.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Widget/Messages.php b/Zotlabs/Widget/Messages.php index 199bd8665..2ba1f4da5 100644 --- a/Zotlabs/Widget/Messages.php +++ b/Zotlabs/Widget/Messages.php @@ -63,6 +63,16 @@ class Messages { $limit = 30; $dummy_order_sql = ''; $loadtime = (($offset) ? $_SESSION['messages_loadtime'] : datetime_convert()); + $vnotify = get_pconfig(local_channel(), 'system', 'vnotify', -1); + + $vnotify_sql = ''; + + if (!($vnotify & VNOTIFY_LIKE)) { + $vnotify_sql = " AND verb NOT IN ('" . dbesc(ACTIVITY_LIKE) . "', '" . dbesc(ACTIVITY_DISLIKE) . "') "; + } + elseif (!feature_enabled(local_channel(), 'dislike')) { + $vnotify_sql = " AND verb NOT IN ('" . dbesc(ACTIVITY_DISLIKE) . "') "; + } switch($type) { case 'direct': @@ -151,7 +161,8 @@ class Messages { $unseen = q("SELECT count(id) AS total FROM item WHERE uid = %d AND parent = %d AND item_thread_top = 0 - AND item_unseen = 1", + AND item_unseen = 1 + $vnotify_sql", intval(local_channel()), intval($item['id']) ); @@ -165,6 +176,7 @@ class Messages { $entries[$i]['href'] = z_root() . '/hq/' . gen_link_id($item['mid']); $entries[$i]['icon'] = $icon; $entries[$i]['unseen'] = (($unseen[0]['total']) ? $unseen[0]['total'] : (($item['item_unseen']) ? ' ' : '')); + $entries[$i]['unseen_class'] = (($item['item_unseen']) ? 'bg-primary' : 'bg-secondary'); $i++; } -- cgit v1.2.3 From 6de1aec68304aa82ba33d852df84d9784a8f37b2 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 22 Nov 2022 21:10:11 +0000 Subject: the blue dots were slightly too bold. --- Zotlabs/Widget/Messages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Widget/Messages.php b/Zotlabs/Widget/Messages.php index 2ba1f4da5..c40d294e8 100644 --- a/Zotlabs/Widget/Messages.php +++ b/Zotlabs/Widget/Messages.php @@ -176,7 +176,7 @@ class Messages { $entries[$i]['href'] = z_root() . '/hq/' . gen_link_id($item['mid']); $entries[$i]['icon'] = $icon; $entries[$i]['unseen'] = (($unseen[0]['total']) ? $unseen[0]['total'] : (($item['item_unseen']) ? ' ' : '')); - $entries[$i]['unseen_class'] = (($item['item_unseen']) ? 'bg-primary' : 'bg-secondary'); + $entries[$i]['unseen_class'] = (($item['item_unseen']) ? 'primary' : 'secondary'); $i++; } -- cgit v1.2.3 From 7ec6df495f5e740b16d7bdca89b18a3f6bc78c80 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 24 Nov 2022 16:05:19 +0100 Subject: slight restructure --- Zotlabs/Lib/Webfinger.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/Webfinger.php b/Zotlabs/Lib/Webfinger.php index 16d54010c..a0a4aef47 100644 --- a/Zotlabs/Lib/Webfinger.php +++ b/Zotlabs/Lib/Webfinger.php @@ -52,15 +52,21 @@ class Webfinger { if(strpos($resource,'http') === 0) { $m = parse_url($resource); - if($m) { - if(isset($m['scheme']) && $m['scheme'] !== 'https') { - return false; - } - self::$server = $m['host'] . ((isset($m['port'])) ? ':' . $m['port'] : ''); + + if (!$m) { + return false; } - else { + + if(isset($m['scheme']) && $m['scheme'] !== 'https') { return false; } + + if(!isset($m['host'])) { + return false; + } + + self::$server = $m['host'] . ((isset($m['port'])) ? ':' . $m['port'] : ''); + } elseif(strpos($resource,'tag:') === 0) { $arr = explode(':',$resource); // split the tag -- cgit v1.2.3 From 1e4718eae1c9ce647a34ed13d43d8a0bbe7c42af Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Thu, 24 Nov 2022 16:42:09 +0100 Subject: do not always trigger a sse event if pubs notification are off or the app is not installed for the channel --- Zotlabs/Module/Sse.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Sse.php b/Zotlabs/Module/Sse.php index 3dab3d465..f87a19821 100644 --- a/Zotlabs/Module/Sse.php +++ b/Zotlabs/Module/Sse.php @@ -100,9 +100,9 @@ class Sse extends Controller { // We do not have the local_channel in the addon. // Reset pubs here if the app is not installed. if (self::$uid && (!(self::$vnotify & VNOTIFY_PUBS) || !Apps::system_app_installed(self::$uid, 'Public Stream'))) { - $result['pubs']['count'] = 0; - $result['pubs']['notifications'] = []; - $result['pubs']['offset'] = -1; + if (isset($result['pubs'])) { + unset($result['pubs']); + } } if($result && !$lock) { -- cgit v1.2.3 From 68ca8951a85973cf385f23b6147f51718563d7bf Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 25 Nov 2022 18:37:22 +0000 Subject: mark unseen items seen after a certain amount of time (default 90 days) --- Zotlabs/Daemon/Cron_daily.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Cron_daily.php b/Zotlabs/Daemon/Cron_daily.php index d1b74a032..71d3bc9ef 100644 --- a/Zotlabs/Daemon/Cron_daily.php +++ b/Zotlabs/Daemon/Cron_daily.php @@ -49,6 +49,22 @@ class Cron_daily { dbesc('sse_id.%') ); + // Mark items seen after X days (default 90) + + $r = dbq("select channel_id from channel where channel_removed = 0"); + if ($r) { + foreach ($r as $rr) { + $mark_seen_days = get_pconfig($rr['channel_id'], 'system', 'mark_seen_days', 90); + q("UPDATE item SET item_unseen = 0 WHERE + uid = %d AND item_unseen = 1 + AND created < %s - INTERVAL %s", + intval($rr['channel_id']), + db_utcnow(), + db_quoteinterval($mark_seen_days . ' DAY') + ); + } + } + // Clean up emdedded content cache q("DELETE FROM cache WHERE updated < %s - INTERVAL %s", db_utcnow(), -- cgit v1.2.3 From a050e8c8f50dd84ca7259ae1ceb3511a73ba06ba Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 26 Nov 2022 08:37:45 +0000 Subject: should compare against abook_updated to make sure we do not always poll broken feeds --- Zotlabs/Daemon/Poller.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Poller.php b/Zotlabs/Daemon/Poller.php index 702c940a3..63c498f17 100644 --- a/Zotlabs/Daemon/Poller.php +++ b/Zotlabs/Daemon/Poller.php @@ -101,12 +101,14 @@ class Poller { $x = datetime_convert('UTC', 'UTC', "now - $min minutes"); - if ($c < $x) { + if ($t < $x) { Master::Summon(['Onepoll', $contact['abook_id']]); if ($interval) @time_sleep_until(microtime(true) + (float)$interval); } + continue; + } if ($contact['xchan_network'] !== 'zot6') -- cgit v1.2.3 From 2de2c8e207aae66280a7be6bccfe64558534a54e Mon Sep 17 00:00:00 2001 From: Harald Eilertsen Date: Sat, 26 Nov 2022 15:45:37 +0100 Subject: Fix Category widget URLs The category widget template expects a URL without any query params, as it appends `/?cat=` to the base URL passed to it. The Widget code tried to preserve any query param passed to it except for the `cat` query param. When passed to the template, this caused the invalid URLs to be generated. Example input url: https://example.com/channel/user?f=&tag=pasta The URL generated for the "Dinner" category would then be: https://example.com/channel/user&tag=pasta&tag=pasta/?cat=Dinner Which is troublesome in more than one way, and cause at least some search bots to go wild by sending requests with increasingly long URLs. This patch will simply discard the existing query params in the URL, so with the same input url, the generated URL for the "Dinner" category will now be: https://example.com/channel/user/?cat=Dinner This is comparable to what the Category Cloud and Tag Cloud widgets already do. --- Zotlabs/Widget/Categories.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Widget/Categories.php b/Zotlabs/Widget/Categories.php index b31856e48..b0eda253b 100644 --- a/Zotlabs/Widget/Categories.php +++ b/Zotlabs/Widget/Categories.php @@ -24,15 +24,16 @@ class Categories { } $cat = ((x($_REQUEST, 'cat')) ? htmlspecialchars($_REQUEST['cat'], ENT_COMPAT, 'UTF-8') : ''); - $srchurl = App::$query_string; - $srchurl = rtrim(preg_replace('/cat\=[^\&].*?(\&|$)/is', '', $srchurl), '&'); - $srchurl = str_replace(['?f=','&f=', '/?'], ['', '', ''], $srchurl); + + // Discard queries from the current URL, as the template expects a base + // URL without any queries. + $base = substr(App::$query_string, 0, strcspn(App::$query_string, '?')); if($files) { - return filecategories_widget($srchurl, $cat); + return filecategories_widget($base, $cat); } - return categories_widget($srchurl, $cat); + return categories_widget($base, $cat); } } -- cgit v1.2.3 From 4002531b9296f764c20da2f50ff1bb5feef6dccb Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 29 Nov 2022 10:00:07 +0000 Subject: fix issue where site_firehose setting was always false --- Zotlabs/Module/Pubstream.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Pubstream.php b/Zotlabs/Module/Pubstream.php index 3c8dfa0a5..47da3c13a 100644 --- a/Zotlabs/Module/Pubstream.php +++ b/Zotlabs/Module/Pubstream.php @@ -12,6 +12,7 @@ class Pubstream extends \Zotlabs\Web\Controller { function get($update = 0, $load = false) { + if(local_channel()) { if(! Apps::system_app_installed(local_channel(), 'Public Stream')) { //Do not display any associated widgets at this point @@ -31,16 +32,13 @@ class Pubstream extends \Zotlabs\Web\Controller { } } - $site_firehose = ((intval(get_config('system','site_firehose',0))) ? true : false); $net_firehose = ((get_config('system','disable_discover_tab',1)) ? false : true); - if(! ($site_firehose || $net_firehose)) { + if(!$net_firehose) { return ''; } - if($net_firehose) { - $site_firehose = false; - } + $site_firehose = ((intval(get_config('system','site_firehose',0))) ? true : false); $mid = ((x($_REQUEST, 'mid')) ? unpack_link_id($_REQUEST['mid']) : ''); if ($mid === false) { @@ -161,13 +159,14 @@ class Pubstream extends \Zotlabs\Web\Controller { $sys = get_sys_channel(); $abook_uids = " and abook.abook_channel = " . intval($sys['channel_id']) . " "; + $sql_extra = ''; if($site_firehose) { $uids = " and item.uid in ( " . stream_perms_api_uids(PERMS_PUBLIC) . " ) and item_private = 0 and item_wall = 1 "; } else { $uids = " and item.uid = " . intval($sys['channel_id']) . " "; - $sql_extra = item_permissions_sql($sys['channel_id']); + $sql_extra .= item_permissions_sql($sys['channel_id']); \App::$data['firehose'] = intval($sys['channel_id']); } -- cgit v1.2.3 From 3ce1373ae0e5355b9d10eab5f5b8078245c4b8b6 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 30 Nov 2022 09:18:57 +0000 Subject: provide a pdl file for mod invite and set the profile --- Zotlabs/Module/Invite.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Invite.php b/Zotlabs/Module/Invite.php index 2a126ac27..bb552e4c7 100644 --- a/Zotlabs/Module/Invite.php +++ b/Zotlabs/Module/Invite.php @@ -43,6 +43,19 @@ class Invite extends Controller { const MYP = 'ZAI'; const VERSION = '2.0.0'; + function init() { + + if (!local_channel()) { + return; + } + + $channel = App::get_channel(); + if ($channel) { + profile_load($channel['channel_address']); + } + + } + function post() { // zai02 -- cgit v1.2.3 From baf1b8b02de4ef3d62a2fd9126cbc05de1bf8711 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 30 Nov 2022 10:36:55 +0000 Subject: fetch the unseen count in a subquery instead of a separate query and rename array key --- Zotlabs/Widget/Messages.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Widget/Messages.php b/Zotlabs/Widget/Messages.php index c40d294e8..414353d8a 100644 --- a/Zotlabs/Widget/Messages.php +++ b/Zotlabs/Widget/Messages.php @@ -35,7 +35,7 @@ class Messages { 'notice_messages_title' => t('Notices'), 'loading' => t('Loading'), 'empty' => t('No messages'), - 'unseen' => t('Unseen') + 'unseen_count' => t('Unseen') ] ]); @@ -88,7 +88,9 @@ class Messages { $type_sql = ' AND item_private IN (0, 1) '; } - $items = q("SELECT * FROM item WHERE uid = %d + $items = q("SELECT item.*, parent AS this_parent, + (SELECT count(*) FROM item WHERE uid = %d AND parent = this_parent AND item_unseen = 1 AND item_thread_top = 0 $vnotify_sql) AS unseen_count + FROM item WHERE uid = %d AND created <= '%s' $type_sql AND item_thread_top = 1 @@ -96,6 +98,7 @@ class Messages { ORDER BY created DESC $dummy_order_sql LIMIT $limit OFFSET $offset", intval(local_channel()), + intval(local_channel()), dbescdate($loadtime) ); @@ -158,15 +161,6 @@ class Messages { $icon = ''; } - $unseen = q("SELECT count(id) AS total FROM item WHERE uid = %d - AND parent = %d - AND item_thread_top = 0 - AND item_unseen = 1 - $vnotify_sql", - intval(local_channel()), - intval($item['id']) - ); - $entries[$i]['author_name'] = $item['author']['xchan_name']; $entries[$i]['author_addr'] = (($item['author']['xchan_addr']) ? $item['author']['xchan_addr'] : $item['author']['xchan_url']); $entries[$i]['info'] = $info; @@ -175,7 +169,7 @@ class Messages { $entries[$i]['b64mid'] = gen_link_id($item['mid']); $entries[$i]['href'] = z_root() . '/hq/' . gen_link_id($item['mid']); $entries[$i]['icon'] = $icon; - $entries[$i]['unseen'] = (($unseen[0]['total']) ? $unseen[0]['total'] : (($item['item_unseen']) ? ' ' : '')); + $entries[$i]['unseen_count'] = (($item['unseen_count']) ? $item['unseen_count'] : (($item['item_unseen']) ? ' ' : '')); $entries[$i]['unseen_class'] = (($item['item_unseen']) ? 'primary' : 'secondary'); $i++; -- cgit v1.2.3 From e4461f2e61198fdc6002d7b2b36185c0f275e58d Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 30 Nov 2022 11:20:10 +0000 Subject: adjust the query to work with postgres --- Zotlabs/Widget/Messages.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Widget/Messages.php b/Zotlabs/Widget/Messages.php index 414353d8a..0f57a8d85 100644 --- a/Zotlabs/Widget/Messages.php +++ b/Zotlabs/Widget/Messages.php @@ -58,7 +58,7 @@ class Messages { } $channel = App::get_channel(); - $item_normal = item_normal(); + $item_normal = str_replace('item.', 'i.', item_normal()); $entries = []; $limit = 30; $dummy_order_sql = ''; @@ -68,34 +68,34 @@ class Messages { $vnotify_sql = ''; if (!($vnotify & VNOTIFY_LIKE)) { - $vnotify_sql = " AND verb NOT IN ('" . dbesc(ACTIVITY_LIKE) . "', '" . dbesc(ACTIVITY_DISLIKE) . "') "; + $vnotify_sql = " AND c.verb NOT IN ('" . dbesc(ACTIVITY_LIKE) . "', '" . dbesc(ACTIVITY_DISLIKE) . "') "; } elseif (!feature_enabled(local_channel(), 'dislike')) { - $vnotify_sql = " AND verb NOT IN ('" . dbesc(ACTIVITY_DISLIKE) . "') "; + $vnotify_sql = " AND c.verb NOT IN ('" . dbesc(ACTIVITY_DISLIKE) . "') "; } switch($type) { case 'direct': - $type_sql = ' AND item_private = 2 '; + $type_sql = ' AND i.item_private = 2 '; // $dummy_order_sql has no other meaning but to trick // some mysql backends into using the right index. - $dummy_order_sql = ', received DESC '; + $dummy_order_sql = ', i.received DESC '; break; case 'starred': - $type_sql = ' AND item_starred = 1 '; + $type_sql = ' AND i.item_starred = 1 '; break; default: - $type_sql = ' AND item_private IN (0, 1) '; + $type_sql = ' AND i.item_private IN (0, 1) '; } - $items = q("SELECT item.*, parent AS this_parent, - (SELECT count(*) FROM item WHERE uid = %d AND parent = this_parent AND item_unseen = 1 AND item_thread_top = 0 $vnotify_sql) AS unseen_count - FROM item WHERE uid = %d - AND created <= '%s' + $items = q("SELECT *, + (SELECT count(*) FROM item c WHERE c.uid = %d AND c.parent = i.parent AND c.item_unseen = 1 AND c.item_thread_top = 0 $vnotify_sql) AS unseen_count + FROM item i WHERE i.uid = %d + AND i.created <= '%s' $type_sql - AND item_thread_top = 1 + AND i.item_thread_top = 1 $item_normal - ORDER BY created DESC $dummy_order_sql + ORDER BY i.created DESC $dummy_order_sql LIMIT $limit OFFSET $offset", intval(local_channel()), intval(local_channel()), -- cgit v1.2.3 From 2bb58843ab303ba3e1a4a2c0c5a64138852ebbe0 Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 2 Dec 2022 19:22:19 +0000 Subject: move queueworker to core and bump version --- Zotlabs/Daemon/Cron.php | 8 +- Zotlabs/Daemon/Master.php | 11 ++ Zotlabs/Daemon/Poller.php | 16 +- Zotlabs/Lib/Libsync.php | 9 +- Zotlabs/Lib/QueueWorker.php | 351 +++++++++++++++++++++++++++++++++++++++++ Zotlabs/Module/Import.php | 2 +- Zotlabs/Module/Queueworker.php | 122 ++++++++++++++ Zotlabs/Update/_1254.php | 55 +++++++ 8 files changed, 569 insertions(+), 5 deletions(-) create mode 100644 Zotlabs/Lib/QueueWorker.php create mode 100644 Zotlabs/Module/Queueworker.php create mode 100644 Zotlabs/Update/_1254.php (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Cron.php b/Zotlabs/Daemon/Cron.php index 6629491de..c3158a4eb 100644 --- a/Zotlabs/Daemon/Cron.php +++ b/Zotlabs/Daemon/Cron.php @@ -50,7 +50,7 @@ class Cron { require_once('include/account.php'); remove_expired_registrations(); - $interval = get_config('system', 'delivery_interval', 3); + //$interval = get_config('system', 'delivery_interval', 3); // expire any expired items @@ -65,8 +65,10 @@ class Cron { if ($rr['item_wall']) { // The notifier isn't normally invoked unless item_drop is interactive. Master::Summon(['Notifier', 'drop', $rr['id']]); + /* if ($interval) @time_sleep_until(microtime(true) + (float)$interval); + */ } } } @@ -96,8 +98,10 @@ class Cron { if ($r) { foreach ($r as $rr) { Master::Summon(array('Directory', $rr['channel_id'], 'force')); + /* if ($interval) @time_sleep_until(microtime(true) + (float)$interval); + */ } } @@ -151,8 +155,10 @@ class Cron { ); } Master::Summon(array('Notifier', 'wall-new', $rr['id'])); + /* if ($interval) @time_sleep_until(microtime(true) + (float)$interval); + */ } } } diff --git a/Zotlabs/Daemon/Master.php b/Zotlabs/Daemon/Master.php index 6fa656be5..495718bf4 100644 --- a/Zotlabs/Daemon/Master.php +++ b/Zotlabs/Daemon/Master.php @@ -2,6 +2,8 @@ namespace Zotlabs\Daemon; +use Zotlabs\Lib\QueueWorker; + if (array_search(__file__, get_included_files()) === 0) { require_once('include/cli_startup.php'); array_shift($argv); @@ -16,6 +18,10 @@ if (array_search(__file__, get_included_files()) === 0) { class Master { static public function Summon($arr) { + + QueueWorker::Summon($arr); + return; +/* $hookinfo = [ 'argv' => $arr ]; @@ -32,11 +38,15 @@ class Master { $phpbin = get_config('system', 'phpbin', 'php'); proc_run($phpbin, 'Zotlabs/Daemon/Master.php', $arr); +*/ } static public function Release($argc, $argv) { cli_startup(); + QueueWorker::Release($argv); + return; +/* $hookinfo = [ 'argv' => $argv ]; @@ -54,5 +64,6 @@ class Master { logger('Master: release: ' . json_encode($argv), LOGGER_ALL, LOG_DEBUG); $cls = '\\Zotlabs\\Daemon\\' . $argv[0]; $cls::run($argc, $argv); +*/ } } diff --git a/Zotlabs/Daemon/Poller.php b/Zotlabs/Daemon/Poller.php index 63c498f17..5bf8d3a02 100644 --- a/Zotlabs/Daemon/Poller.php +++ b/Zotlabs/Daemon/Poller.php @@ -17,10 +17,12 @@ class Poller { } } +/* $interval = intval(get_config('system', 'poll_interval')); if (!$interval) $interval = ((get_config('system', 'delivery_interval') === false) ? 3 : intval(get_config('system', 'delivery_interval'))); + // Check for a lockfile. If it exists, but is over an hour old, it's stale. Ignore it. $lockfile = 'store/[data]/poller'; if ((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600)) @@ -32,6 +34,7 @@ class Poller { // Create a lockfile. Needs two vars, but $x doesn't need to contain anything. $x = ''; file_put_contents($lockfile, $x); +*/ logger('poller: start'); @@ -103,8 +106,10 @@ class Poller { if ($t < $x) { Master::Summon(['Onepoll', $contact['abook_id']]); + /* if ($interval) @time_sleep_until(microtime(true) + (float)$interval); + */ } continue; @@ -167,8 +172,11 @@ class Poller { continue; Master::Summon(['Onepoll', $contact['abook_id']]); + + /* if ($interval) @time_sleep_until(microtime(true) + (float)$interval); + */ } } @@ -190,9 +198,13 @@ class Poller { if ($rr['ud_last'] > NULL_DATE) if ($rr['ud_last'] > datetime_convert('UTC', 'UTC', 'now - 1 day')) continue; + Master::Summon(['Onedirsync', $rr['ud_id']]); + + /* if ($interval) @time_sleep_until(microtime(true) + (float)$interval); + */ } } } @@ -200,9 +212,9 @@ class Poller { set_config('system', 'lastpoll', datetime_convert()); //All done - clear the lockfile - +/* @unlink($lockfile); - +*/ return; } } diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php index fd9886f71..b02ae4c69 100644 --- a/Zotlabs/Lib/Libsync.php +++ b/Zotlabs/Lib/Libsync.php @@ -135,8 +135,10 @@ class Libsync { $info['collection_members'] = $r; } + /* $interval = ((get_config('system', 'delivery_interval') !== false) ? intval(get_config('system', 'delivery_interval')) : 2); + */ logger('Packet: ' . print_r($info, true), LOGGER_DATA, LOG_DEBUG); @@ -155,19 +157,24 @@ class Libsync { ]); + /* $x = q("select count(outq_hash) as total from outq where outq_delivered = 0"); + if (intval($x[0]['total']) > intval(get_config('system', 'force_queue_threshold', 3000))) { logger('immediate delivery deferred.', LOGGER_DEBUG, LOG_INFO); Queue::update($hash); continue; } - + */ Master::Summon(['Deliver', $hash]); + + /* $total = $total - 1; if ($interval && $total) @time_sleep_until(microtime(true) + (float)$interval); + */ } } diff --git a/Zotlabs/Lib/QueueWorker.php b/Zotlabs/Lib/QueueWorker.php new file mode 100644 index 000000000..21983a4e2 --- /dev/null +++ b/Zotlabs/Lib/QueueWorker.php @@ -0,0 +1,351 @@ + 10, + 'Deliver' => 10, + 'Cache_query' => 10, + 'Content_importer' => 1, + 'File_importer' => 1, + 'Channel_purge' => 1, + 'Directory' => 1 + ]; + + private static function qbegin($tablename) { + switch (ACTIVE_DBTYPE) { + case DBTYPE_MYSQL: + q('BEGIN'); + q('LOCK TABLE ' . $tablename . ' WRITE'); + break; + + case DBTYPE_POSTGRES: + q('BEGIN'); + //q('LOCK TABLE '.$tablename.' IN ACCESS EXCLUSIVE MODE'); + break; + } + return; + } + + private static function qcommit() { + switch (ACTIVE_DBTYPE) { + case DBTYPE_MYSQL: + q("UNLOCK TABLES"); + q("COMMIT"); + break; + + case DBTYPE_POSTGRES: + q("COMMIT"); + break; + } + return; + } + + private static function qrollback() { + switch (ACTIVE_DBTYPE) { + case DBTYPE_MYSQL: + q("ROLLBACK"); + q("UNLOCK TABLES"); + break; + + case DBTYPE_POSTGRES: + q("ROLLBACK"); + break; + } + return; + } + + public static function Summon(&$argv) { + + $argc = count($argv); + + if ($argv[0] !== 'Queueworker') { + + $priority = 0; // @TODO allow reprioritization + + if(isset(self::$default_priorities[$argv[0]])) { + $priority = self::$default_priorities[$argv[0]]; + } + + $workinfo = ['argc' => $argc, 'argv' => $argv]; + $workinfo_json = json_encode($workinfo); + $uuid = self::getUuid($workinfo_json); + + $r = q("SELECT * FROM workerq WHERE workerq_uuid = '%s'", + dbesc($uuid) + ); + if ($r) { + logger("Summon: Ignoring duplicate workerq task", LOGGER_DEBUG); + logger(print_r($workinfo,true)); + $argv = []; + return; + } + + self::qbegin('workerq'); + $r = q("INSERT INTO workerq (workerq_priority, workerq_data, workerq_uuid) VALUES (%d, '%s', '%s')", + intval($priority), + $workinfo_json, + dbesc($uuid) + ); + if (!$r) { + self::qrollback(); + logger("INSERT FAILED", LOGGER_DEBUG); + return; + } + self::qcommit(); + logger('INSERTED: ' . $workinfo_json, LOGGER_DEBUG); + } + $argv = []; + + $workers = self::GetWorkerCount(); + if ($workers < self::$maxworkers) { + logger("Less than max active workers ($workers) max = " . self::$maxworkers . ".", LOGGER_DEBUG); + $phpbin = get_config('system', 'phpbin', 'php'); + proc_run($phpbin, 'Zotlabs/Daemon/Master.php', ['Queueworker']); + } + } + + public static function Release(&$argv) { + + $argc = count($argv); + + if ($argv[0] !== 'Queueworker') { + + $priority = 0; // @TODO allow reprioritization + if(isset(self::$default_priorities[$argv[0]])) { + $priority = self::$default_priorities[$argv[0]]; + } + + $workinfo = ['argc' => $argc, 'argv' => $argv]; + $workinfo_json = json_encode($workinfo); + $uuid = self::getUuid($workinfo_json); + + $r = q("SELECT * FROM workerq WHERE workerq_uuid = '%s'", + dbesc($uuid) + ); + if ($r) { + logger("Release: Duplicate task - do not insert.", LOGGER_DEBUG); + logger(print_r($workinfo,true)); + + $argv = []; + return; + } + + self::qbegin('workerq'); + $r = q("INSERT INTO workerq (workerq_priority, workerq_data, workerq_uuid) VALUES (%d, '%s', '%s')", + intval($priority), + $workinfo_json, + dbesc($uuid) + ); + if (!$r) { + self::qrollback(); + logger("Insert failed: " . $workinfo_json, LOGGER_DEBUG); + return; + } + self::qcommit(); + logger('INSERTED: ' . $workinfo_json, LOGGER_DEBUG); + } + $argv = []; + self::Process(); + } + + public static function GetWorkerCount() { + if (self::$maxworkers == 0) { + self::$maxworkers = get_config('queueworker', 'max_queueworkers', 4); + self::$maxworkers = self::$maxworkers > 3 ? self::$maxworkers : 4; + } + if (self::$workermaxage == 0) { + self::$workermaxage = get_config('queueworker', 'max_queueworker_age'); + self::$workermaxage = self::$workermaxage > 120 ? self::$workermaxage : 300; + } + + q("update workerq set workerq_reservationid = null where workerq_reservationid is not null and workerq_processtimeout < %s", + db_utcnow() + ); + + usleep(self::$workersleep); + $workers = dbq("select count(distinct workerq_reservationid) as total from workerq where workerq_reservationid is not null"); + logger("WORKERCOUNT: " . $workers[0]['total'], LOGGER_DEBUG); + return intval($workers[0]['total']); + } + + public static function GetWorkerID() { + if (self::$queueworker) { + return self::$queueworker; + } + $wid = uniqid('', true); + usleep(mt_rand(500000, 3000000)); //Sleep .5 - 3 seconds before creating a new worker. + $workers = self::GetWorkerCount(); + if ($workers >= self::$maxworkers) { + logger("Too many active workers ($workers) max = " . self::$maxworkers, LOGGER_DEBUG); + return false; + } + self::$queueworker = $wid; + return $wid; + } + + private static function getWorkId() { + self::GetWorkerCount(); + + self::qbegin('workerq'); + + if (ACTIVE_DBTYPE == DBTYPE_POSTGRES) { + $work = dbq("SELECT workerq_id FROM workerq WHERE workerq_reservationid IS NULL ORDER BY workerq_priority DESC, workerq_id ASC LIMIT 1 FOR UPDATE SKIP LOCKED;"); + } + else { + $work = dbq("SELECT workerq_id FROM workerq WHERE workerq_reservationid IS NULL ORDER BY workerq_priority DESC, workerq_id ASC LIMIT 1;"); + } + + if (!$work) { + self::qrollback(); + return false; + } + $id = $work[0]['workerq_id']; + + $work = q("UPDATE workerq SET workerq_reservationid = '%s', workerq_processtimeout = %s + INTERVAL %s WHERE workerq_id = %d", + self::$queueworker, + db_utcnow(), + db_quoteinterval(self::$workermaxage . " SECOND"), + intval($id) + ); + + if (!$work) { + self::qrollback(); + logger("Could not update workerq.", LOGGER_DEBUG); + return false; + } + logger("GOTWORK: " . json_encode($work), LOGGER_DEBUG); + self::qcommit(); + return $id; + } + + public static function Process() { + self::$workersleep = get_config('queueworker', 'queue_worker_sleep'); + self::$workersleep = intval(self::$workersleep) > 100 ? intval(self::$workersleep) : 100; + + if (!self::GetWorkerID()) { + logger('Unable to get worker ID. Exiting.', LOGGER_DEBUG); + killme(); + } + + $jobs = 0; + $workid = self::getWorkId(); + while ($workid) { + usleep(self::$workersleep); + // @FIXME: Currently $workersleep is a fixed value. It may be a good idea + // to implement a "backoff" instead - based on load average or some + // other metric. + + self::qbegin('workerq'); + + if (ACTIVE_DBTYPE == DBTYPE_POSTGRES) { + $workitem = q("SELECT * FROM workerq WHERE workerq_id = %d FOR UPDATE SKIP LOCKED", + $workid + ); + } + else { + $workitem = q("SELECT * FROM workerq WHERE workerq_id = %d", + $workid + ); + } + + self::qcommit(); + + if (isset($workitem[0])) { + // At least SOME work to do.... in case there's more, let's ramp up workers. + $workers = self::GetWorkerCount(); + if ($workers < self::$maxworkers) { + logger("Less than max active workers ($workers) max = " . self::$maxworkers . ".", LOGGER_DEBUG); + $phpbin = get_config('system', 'phpbin', 'php'); + proc_run($phpbin, 'Zotlabs/Daemon/Master.php', ['Queueworker']); + } + + $jobs++; + logger("Workinfo: " . $workitem[0]['workerq_data'], LOGGER_DEBUG); + + $workinfo = json_decode($workitem[0]['workerq_data'], true); + $argv = $workinfo['argv']; + logger('Master: process: ' . json_encode($argv), LOGGER_DEBUG); + + $cls = '\\Zotlabs\\Daemon\\' . $argv[0]; + $argv = flatten_array_recursive($argv); + $argc = count($argv); + $cls::run($argc, $argv); + + // @FIXME: Right now we assume that if we get a return, everything is OK. + // At some point we may want to test whether the run returns true/false + // and requeue the work to be tried again if needed. But we probably want + // to implement some sort of "retry interval" first. + + self::qbegin('workerq'); + q("delete from workerq where workerq_id = %d", $workid); + self::qcommit(); + } + else { + logger("NO WORKITEM!", LOGGER_DEBUG); + } + $workid = self::getWorkId(); + } + logger('Master: Worker Thread: queue items processed:' . $jobs, LOGGER_DEBUG); + } + + public static function ClearQueue() { + $work = q("select * from workerq"); + while ($work) { + foreach ($work as $workitem) { + $workinfo = json_decode($workitem['v'], true); + $argc = $workinfo['argc']; + $argv = $workinfo['argv']; + logger('Master: process: ' . print_r($argv, true), LOGGER_ALL, LOG_DEBUG); + if (!isset($argv[0])) { + q("delete from workerq where workerq_id = %d", + $work[0]['workerq_id'] + ); + continue; + } + $cls = '\\Zotlabs\\Daemon\\' . $argv[0]; + $cls::run($argc, $argv); + q("delete from workerq where workerq_id = %d", + $work[0]['workerq_id'] + ); + usleep(300000); + //Give the server .3 seconds to catch its breath between tasks. + //This will hopefully keep it from crashing to it's knees entirely + //if the last task ended up initiating other parallel processes + //(eg. polling remotes) + } + //Make sure nothing new came in + $work = q("select * from workerq"); + } + return; + } + + /** + * @brief Generate a name-based v5 UUID with custom namespace + * + * @param string $data + * @return string $uuid + */ + private static function getUuid($data) { + $namespace = '3a112e42-f147-4ccf-a78b-f6841339ea2a'; + try { + $uuid = Uuid::uuid5($namespace, $data)->toString(); + } catch (UnableToBuildUuidException $e) { + logger('UUID generation failed'); + return ''; + } + return $uuid; + } + +} diff --git a/Zotlabs/Module/Import.php b/Zotlabs/Module/Import.php index ec47e370b..c8a9ac5ed 100644 --- a/Zotlabs/Module/Import.php +++ b/Zotlabs/Module/Import.php @@ -536,7 +536,7 @@ class Import extends Controller { $since = datetime_convert(date_default_timezone_get(), date_default_timezone_get(), '0001-01-01 00:00'); $until = datetime_convert(date_default_timezone_get(), date_default_timezone_get(), 'now + 1 day'); - $poll_interval = get_config('system', 'poll_interval', 3); + //$poll_interval = get_config('system', 'poll_interval', 3); $page = 0; Master::Summon(['Content_importer', sprintf('%d', $page), $since, $until, $channel['channel_address'], urlencode($hz_server)]); diff --git a/Zotlabs/Module/Queueworker.php b/Zotlabs/Module/Queueworker.php new file mode 100644 index 000000000..808a9ed61 --- /dev/null +++ b/Zotlabs/Module/Queueworker.php @@ -0,0 +1,122 @@ + 3) ? $maxqueueworkers : 4; + set_config('queueworker', 'max_queueworkers', $maxqueueworkers); + + $maxworkerage = intval($_POST['queueworker_max_age']); + $maxworkerage = ($maxworkerage >= 120) ? $maxworkerage : 300; + set_config('queueworker', 'queueworker_max_age', $maxworkerage); + + $queueworkersleep = intval($_POST['queue_worker_sleep']); + $queueworkersleep = ($queueworkersleep > 100) ? $queueworkersleep : 100; + set_config('queueworker', 'queue_worker_sleep', $queueworkersleep); + + goaway(z_root() . '/queueworker'); + } + + function get() { + + $content = "

ERROR: Page not found

"; + App::$error = 404; + + if (!local_channel()) { + return $content; + } + + if (!(is_site_admin())) { + return $content; + } + + load_config("queueworker"); + + $content = "

Queue Status

\n"; + + $r = q('select count(*) as qentries from workerq'); + + if (!$r) { + $content = "

There was an error querying the database.

"; + return $content; + } + + $content .= "

There are " . $r[0]['qentries'] . " queue items to be processed.

"; + + $r = dbq("select count(distinct workerq_reservationid) as qworkers from workerq where workerq_reservationid is not null"); + + $content .= "

Active workers: " . $r[0]['qworkers'] . "

"; + + $maxqueueworkers = get_config('queueworker', 'max_queueworkers', 4); + $maxqueueworkers = ($maxqueueworkers > 3) ? $maxqueueworkers : 4; + set_config('queueworker', 'max_queueworkers', $maxqueueworkers); + + $sc = ''; + + $sc .= replace_macros(get_markup_template('field_input.tpl'), [ + '$field' => [ + 'queueworker_maxworkers', + t('Max queueworker threads'), + $maxqueueworkers, + t('Minimum 4, default 4') + ] + ]); + + $workermaxage = get_config('queueworker', 'queueworker_max_age'); + $workermaxage = ($workermaxage >= 120) ? $workermaxage : 300; + set_config('queueworker', 'max_queueworker_age', $workermaxage); + + $sc .= replace_macros(get_markup_template('field_input.tpl'), [ + '$field' => [ + 'queueworker_max_age', + t('Assume workers dead after'), + $workermaxage, + t('Minimum 120, default 300 seconds') + ] + ]); + + $queueworkersleep = get_config('queueworker', 'queue_worker_sleep'); + $queueworkersleep = ($queueworkersleep > 100) ? $queueworkersleep : 100; + set_config('queueworker', 'queue_worker_sleep', $queueworkersleep); + + $sc .= replace_macros(get_markup_template('field_input.tpl'), [ + '$field' => [ + 'queue_worker_sleep', + t('Pause before starting next task'), + $queueworkersleep, + t('Minimum 100, default 100 microseconds') + ] + ]); + + $tpl = get_markup_template('settings_addon.tpl'); + $content .= replace_macros($tpl, [ + '$action_url' => 'queueworker', + '$form_security_token' => get_form_security_token('queueworker'), + '$title' => t('Queueworker Settings'), + '$content' => $sc, + '$baseurl' => z_root(), + '$submit' => t('Save') + ] + ); + + return $content; + + } +} diff --git a/Zotlabs/Update/_1254.php b/Zotlabs/Update/_1254.php new file mode 100644 index 000000000..ec54754c0 --- /dev/null +++ b/Zotlabs/Update/_1254.php @@ -0,0 +1,55 @@ + Date: Fri, 2 Dec 2022 19:29:46 +0000 Subject: fix typos --- Zotlabs/Update/_1254.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Update/_1254.php b/Zotlabs/Update/_1254.php index ec54754c0..f316fe65b 100644 --- a/Zotlabs/Update/_1254.php +++ b/Zotlabs/Update/_1254.php @@ -22,7 +22,7 @@ class _1254 { $r2 = dbq("CREATE INDEX idx_workerq_priority ON workerq (workerq_priority)"); $r3 = dbq("CREATE INDEX idx_workerq_reservationid ON workerq (workerq_reservationid)"); $r4 = dbq("CREATE INDEX idx_workerq_processtimeout ON workerq (workerq_processtimeout)"); - $r5 = dbq("CREATE INDEX idx_workerq_uuid ON workerq (workerq_uuid)") + $r5 = dbq("CREATE INDEX idx_workerq_uuid ON workerq (workerq_uuid)"); $r = ($r1 && $r2 && $r3 && $r4 && $r5); } @@ -33,11 +33,11 @@ class _1254 { workerq_reservationid varchar(25) DEFAULT NULL, workerq_processtimeout datetime NOT NULL DEFAULT '0001-01-01 00:00:00', workerq_data text, - workerq_uuid char(36) NOT NULL DEFAULT '' + workerq_uuid char(36) NOT NULL DEFAULT '', KEY workerq_priority (workerq_priority), KEY workerq_reservationid (workerq_reservationid), - KEY workerq_processtimeout (workerq_uuid) - KEY workerq_uuid` (workerq_processtimeout) + KEY workerq_processtimeout (workerq_uuid), + KEY workerq_uuid (workerq_processtimeout) ) ENGINE = InnoDB DEFAULT CHARSET=utf8mb4" ); } -- cgit v1.2.3 From 539b69d507d609e15d4cc0ff9cc7ee3ca858deb1 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 3 Dec 2022 08:53:53 +0000 Subject: look for iconfig at the right place, fix mod sharedwithme, comment out unused configs --- Zotlabs/Lib/Activity.php | 8 ++++--- Zotlabs/Module/Admin/Site.php | 18 +++++++-------- Zotlabs/Module/Sharedwithme.php | 51 ++++++++++++++--------------------------- 3 files changed, 31 insertions(+), 46 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 9dbb15c28..8f4e0444c 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -672,6 +672,7 @@ class Activity { } } } + return $ret; } @@ -2456,7 +2457,7 @@ class Activity { $s['attach'] = $a; } - $a = self::decode_iconfig($act->obj); + $a = self::decode_iconfig($act->data); if ($a) { $s['iconfig'] = $a; } @@ -2786,8 +2787,9 @@ class Activity { set_iconfig($s, 'diaspora', 'fields', $diaspora_rawmsg, 1); } - set_iconfig($s, 'activitypub', 'recips', $act->raw_recips); - + if ($act->raw_recips) { + set_iconfig($s, 'activitypub', 'recips', $act->raw_recips); + } $hookinfo = [ 'act' => $act, diff --git a/Zotlabs/Module/Admin/Site.php b/Zotlabs/Module/Admin/Site.php index 85f81e344..7e186fe34 100644 --- a/Zotlabs/Module/Admin/Site.php +++ b/Zotlabs/Module/Admin/Site.php @@ -83,9 +83,9 @@ class Site { $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['proxyuser'])) : ''); $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['proxy'])) : ''); $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60); - $delivery_interval = ((x($_POST,'delivery_interval'))? intval(trim($_POST['delivery_interval'])) : 0); + //$delivery_interval = ((x($_POST,'delivery_interval'))? intval(trim($_POST['delivery_interval'])) : 0); $delivery_batch_count = ((x($_POST,'delivery_batch_count') && $_POST['delivery_batch_count'] > 0)? intval(trim($_POST['delivery_batch_count'])) : 1); - $poll_interval = ((x($_POST,'poll_interval')) ? intval(trim($_POST['poll_interval'])) : 0); + //$poll_interval = ((x($_POST,'poll_interval')) ? intval(trim($_POST['poll_interval'])) : 0); $maxloadavg = ((x($_POST,'maxloadavg')) ? intval(trim($_POST['maxloadavg'])) : 50); $feed_contacts = ((x($_POST,'feed_contacts')) ? intval($_POST['feed_contacts']) : 0); $verify_email = ((x($_POST,'verify_email')) ? 1 : 0); @@ -100,7 +100,7 @@ class Site { $reg_expire = (preg_match('/^[a-z]{1,1}$/', $regexpireu) ? $regexpiren . $regexpireu : ''); $imagick_path = ((x($_POST,'imagick_path')) ? trim($_POST['imagick_path']) : ''); - $force_queue = ((intval($_POST['force_queue']) > 0) ? intval($_POST['force_queue']) : 3000); + //$force_queue = ((intval($_POST['force_queue']) > 0) ? intval($_POST['force_queue']) : 3000); $pub_incl = escape_tags(trim($_POST['pub_incl'])); $pub_excl = escape_tags(trim($_POST['pub_excl'])); @@ -136,9 +136,9 @@ class Site { // <-hilmar] set_config('system', 'feed_contacts', $feed_contacts); - set_config('system', 'delivery_interval', $delivery_interval); + //set_config('system', 'delivery_interval', $delivery_interval); set_config('system', 'delivery_batch_count', $delivery_batch_count); - set_config('system', 'poll_interval', $poll_interval); + //set_config('system', 'poll_interval', $poll_interval); set_config('system', 'maxloadavg', $maxloadavg); set_config('system', 'frontpage', $frontpage); set_config('system', 'sellpage', $site_sellpage); @@ -205,7 +205,7 @@ class Site { set_config('system','disable_discover_tab', $disable_discover_tab); set_config('system','site_firehose', $site_firehose); set_config('system','open_pubstream', $open_pubstream); - set_config('system','force_queue_threshold', $force_queue); + //set_config('system','force_queue_threshold', $force_queue); if ($global_directory == '') { del_config('system', 'directory_submit_url'); } else { @@ -530,10 +530,10 @@ class Site { '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""), '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""), '$timeout' => array('timeout', t("Network timeout"), (x(get_config('system','curl_timeout'))?get_config('system','curl_timeout'):60), t("Value is in seconds. Set to 0 for unlimited (not recommended).")), - '$delivery_interval' => array('delivery_interval', t("Delivery interval"), (x(get_config('system','delivery_interval'))?get_config('system','delivery_interval'):2), t("Delay background delivery processes by this many seconds to reduce system load. Recommend: 4-5 for shared hosts, 2-3 for virtual private servers. 0-1 for large dedicated servers.")), + //'$delivery_interval' => array('delivery_interval', t("Delivery interval"), (x(get_config('system','delivery_interval'))?get_config('system','delivery_interval'):2), t("Delay background delivery processes by this many seconds to reduce system load. Recommend: 4-5 for shared hosts, 2-3 for virtual private servers. 0-1 for large dedicated servers.")), '$delivery_batch_count' => array('delivery_batch_count', t('Deliveries per process'),(x(get_config('system','delivery_batch_count'))?get_config('system','delivery_batch_count'):1), t("Number of deliveries to attempt in a single operating system process. Adjust if necessary to tune system performance. Recommend: 1-5.")), - '$force_queue' => array('force_queue', t("Queue Threshold"), get_config('system','force_queue_threshold',3000), t("Always defer immediate delivery if queue contains more than this number of entries.")), - '$poll_interval' => array('poll_interval', t("Poll interval"), (x(get_config('system','poll_interval'))?get_config('system','poll_interval'):2), t("Delay background polling processes by this many seconds to reduce system load. If 0, use delivery interval.")), + //'$force_queue' => array('force_queue', t("Queue Threshold"), get_config('system','force_queue_threshold',3000), t("Always defer immediate delivery if queue contains more than this number of entries.")), + //'$poll_interval' => array('poll_interval', t("Poll interval"), (x(get_config('system','poll_interval'))?get_config('system','poll_interval'):2), t("Delay background polling processes by this many seconds to reduce system load. If 0, use delivery interval.")), '$imagick_path' => array('imagick_path', t("Path to ImageMagick convert program"), get_config('system','imagick_convert_path'), t("If set, use this program to generate photo thumbnails for huge images ( > 4000 pixels in either dimension), otherwise memory exhaustion may occur. Example: /usr/bin/convert")), '$maxloadavg' => array('maxloadavg', t("Maximum Load Average"), ((intval(get_config('system','maxloadavg')) > 0)?get_config('system','maxloadavg'):50), t("Maximum system load before delivery and poll processes are deferred - default 50.")), '$default_expire_days' => array('default_expire_days', t('Expiration period in days for imported (grid/network) content'), intval(get_config('system','default_expire_days')), t('0 for no expiration of imported content')), diff --git a/Zotlabs/Module/Sharedwithme.php b/Zotlabs/Module/Sharedwithme.php index 4211a3af8..c294079d4 100644 --- a/Zotlabs/Module/Sharedwithme.php +++ b/Zotlabs/Module/Sharedwithme.php @@ -19,13 +19,13 @@ class Sharedwithme extends Controller { notice( t('Permission denied.') . EOL); return; } - + $channel = \App::get_channel(); - + $is_owner = (local_channel() && (local_channel() == $channel['channel_id'])); $item_normal = item_normal(); - + //drop single file - localuser if((argc() > 2) && (argv(2) === 'drop')) { @@ -36,7 +36,7 @@ class Sharedwithme extends Controller { goaway(z_root() . '/sharedwithme'); } - + //drop all files - localuser if((argc() > 1) && (argv(1) === 'dropall')) { @@ -62,33 +62,34 @@ class Sharedwithme extends Controller { dbesc($channel['channel_hash']) ); + $r = fetch_post_tags($r, true); + $items = []; $ids = []; if($r) { - + foreach($r as $rr) { - $object = json_decode($rr['obj'],true); - $meta = self::get_meta($object); + $meta = get_iconfig($rr, 'attach', 'meta'); $item = []; $item['id'] = $rr['id']; $item['objfiletype'] = $meta['type']; $item['objfiletypeclass'] = getIconFromType($meta['type']); $item['objurl'] = $meta['path'] . '?f=&zid=' . $channel['xchan_addr']; - $item['objfilename'] = $object['name']; + $item['objfilename'] = $meta['name']; $item['objfilesize'] = userReadableSize($meta['size']); $item['objedited'] = $meta['edited']; $item['unseen'] = $rr['item_unseen']; - + $items[] = $item; - + if($item['unseen']) { $ids[] = $rr['id']; } - + } - + } $ids = implode(',', $ids); @@ -98,9 +99,9 @@ class Sharedwithme extends Controller { intval(local_channel()) ); } - + $o = ''; - + $o .= replace_macros(get_markup_template('sharedwithme.tpl'), array( '$header' => t('Files: shared with me'), '$name' => t('Name'), @@ -111,27 +112,9 @@ class Sharedwithme extends Controller { '$drop' => t('Remove this file'), '$items' => $items )); - - return $o; - - } - - function get_meta($object) { - - $ret = []; - - if(! is_array($object['attachment'])) - return; - foreach($object['attachment'] as $a) { - if($a['name'] === 'zot.attach.meta') { - $ret = $a['value']; - break; - } - } - - return $ret; + return $o; } - + } -- cgit v1.2.3 From 79e6c9590ab4960661e672dfae8b2e640d2e923b Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 4 Dec 2022 10:27:02 +0000 Subject: the logic for public stream has changed - adjust help text and externals, disable lockfile check in cron daemon --- Zotlabs/Daemon/Cron.php | 10 ++++++---- Zotlabs/Module/Admin/Site.php | 6 +++--- 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Cron.php b/Zotlabs/Daemon/Cron.php index c3158a4eb..9b8946e57 100644 --- a/Zotlabs/Daemon/Cron.php +++ b/Zotlabs/Daemon/Cron.php @@ -19,6 +19,7 @@ class Cron { } } +/* // Check for a lockfile. If it exists, but is over an hour old, it's stale. Ignore it. $lockfile = 'store/[data]/cron'; if ((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600)) @@ -30,6 +31,7 @@ class Cron { // Create a lockfile. Needs two vars, but $x doesn't need to contain anything. $x = ''; file_put_contents($lockfile, $x); +*/ logger('cron: start'); @@ -209,10 +211,10 @@ class Cron { } - // pull in some public posts + // pull in some public posts if allowed - $disable_discover_tab = get_config('system', 'disable_discover_tab') || get_config('system', 'disable_discover_tab') === false; - if (!$disable_discover_tab) + $disable_externals = get_config('system', 'disable_discover_tab') || get_config('system', 'disable_discover_tab') === false || get_config('system', 'site_firehose'); + if (!$disable_externals) Master::Summon(['Externals']); $restart = false; @@ -234,7 +236,7 @@ class Cron { set_config('system', 'lastcron', datetime_convert()); //All done - clear the lockfile - @unlink($lockfile); + //@unlink($lockfile); return; } diff --git a/Zotlabs/Module/Admin/Site.php b/Zotlabs/Module/Admin/Site.php index 7e186fe34..6b93a98f9 100644 --- a/Zotlabs/Module/Admin/Site.php +++ b/Zotlabs/Module/Admin/Site.php @@ -509,9 +509,9 @@ class Site { '$mirror_frontpage' => array('mirror_frontpage', t("Preserve site homepage URL"), get_config('system','mirror_frontpage'), t('Present the site homepage in a frame at the original location instead of redirecting')), '$allowed_sites' => array('allowed_sites', t("Allowed friend domains"), get_config('system','allowed_sites'), t("Comma separated list of domains which are allowed to establish friendships with this site. Wildcards are accepted. Empty to allow any domains")), '$force_publish' => array('publish_all', t("Force publish"), get_config('system','publish_all'), t("Check to force all profiles on this site to be listed in the site directory.")), - '$disable_discover_tab' => array('disable_discover_tab', t('Import Public Streams'), $discover_tab, t('Import and allow access to public content pulled from other sites. Warning: this content is unmoderated.')), - '$site_firehose' => array('site_firehose', t('Site only Public Streams'), get_config('system','site_firehose'), t('Allow access to public content originating only from this site if Imported Public Streams are disabled.')), - '$open_pubstream' => array('open_pubstream', t('Allow anybody on the internet to access the Public streams'), get_config('system','open_pubstream',1), t('Disable to require authentication before viewing. Warning: this content is unmoderated.')), + '$disable_discover_tab' => array('disable_discover_tab', t('Enable public stream'), $discover_tab, t('Enable the public stream. Warning: this content is unmoderated.')), + '$site_firehose' => array('site_firehose', t('Site only public stream'), get_config('system','site_firehose'), t('Only allow public content origianting from this site in the public stream')), + '$open_pubstream' => array('open_pubstream', t('Allow anybody on the internet to access the Public streams'), get_config('system','open_pubstream',1), t('Disable to require authentication before viewing.')), '$incl' => array('pub_incl',t('Only import Public stream posts with this text'), get_config('system','pubstream_incl'),t('words one per line or #tags or /patterns/ or lang=xx, leave blank to import all posts')), '$excl' => array('pub_excl',t('Do not import Public stream posts with this text'), get_config('system','pubstream_excl'),t('words one per line or #tags or /patterns/ or lang=xx, leave blank to import all posts')), -- cgit v1.2.3 From 7a40561aaa2595c1175017cd6e5169869f47fc59 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 4 Dec 2022 10:36:30 +0000 Subject: wording --- Zotlabs/Module/Admin/Site.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Admin/Site.php b/Zotlabs/Module/Admin/Site.php index 6b93a98f9..e518adb17 100644 --- a/Zotlabs/Module/Admin/Site.php +++ b/Zotlabs/Module/Admin/Site.php @@ -508,10 +508,10 @@ class Site { '$frontpage' => array('frontpage', t("Site homepage to show visitors (default: login box)"), get_config('system','frontpage'), t("example: 'pubstream' to show public stream, 'page/sys/home' to show a system webpage called 'home' or 'include:home.html' to include a file.")), '$mirror_frontpage' => array('mirror_frontpage', t("Preserve site homepage URL"), get_config('system','mirror_frontpage'), t('Present the site homepage in a frame at the original location instead of redirecting')), '$allowed_sites' => array('allowed_sites', t("Allowed friend domains"), get_config('system','allowed_sites'), t("Comma separated list of domains which are allowed to establish friendships with this site. Wildcards are accepted. Empty to allow any domains")), - '$force_publish' => array('publish_all', t("Force publish"), get_config('system','publish_all'), t("Check to force all profiles on this site to be listed in the site directory.")), - '$disable_discover_tab' => array('disable_discover_tab', t('Enable public stream'), $discover_tab, t('Enable the public stream. Warning: this content is unmoderated.')), - '$site_firehose' => array('site_firehose', t('Site only public stream'), get_config('system','site_firehose'), t('Only allow public content origianting from this site in the public stream')), - '$open_pubstream' => array('open_pubstream', t('Allow anybody on the internet to access the Public streams'), get_config('system','open_pubstream',1), t('Disable to require authentication before viewing.')), + '$force_publish' => array('publish_all', t("Force publish"), get_config('system','publish_all'), t("Check to force all profiles on this site to be listed in the site directory")), + '$disable_discover_tab' => array('disable_discover_tab', t('Enable public stream'), $discover_tab, t('Enable the public stream. Warning: this content is unmoderated')), + '$site_firehose' => array('site_firehose', t('Site only public stream'), get_config('system','site_firehose'), t('Restrict the public stream to content origianting from this site')), + '$open_pubstream' => array('open_pubstream', t('Allow anybody on the internet to access the public streams'), get_config('system','open_pubstream',1), t('Disable to require authentication before viewing')), '$incl' => array('pub_incl',t('Only import Public stream posts with this text'), get_config('system','pubstream_incl'),t('words one per line or #tags or /patterns/ or lang=xx, leave blank to import all posts')), '$excl' => array('pub_excl',t('Do not import Public stream posts with this text'), get_config('system','pubstream_excl'),t('words one per line or #tags or /patterns/ or lang=xx, leave blank to import all posts')), -- cgit v1.2.3 From 0184d2c292b2ee4d904cb00cc48110b4a79376dd Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 4 Dec 2022 10:43:57 +0000 Subject: typo --- Zotlabs/Module/Admin/Site.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Admin/Site.php b/Zotlabs/Module/Admin/Site.php index e518adb17..e3feee1bb 100644 --- a/Zotlabs/Module/Admin/Site.php +++ b/Zotlabs/Module/Admin/Site.php @@ -510,7 +510,7 @@ class Site { '$allowed_sites' => array('allowed_sites', t("Allowed friend domains"), get_config('system','allowed_sites'), t("Comma separated list of domains which are allowed to establish friendships with this site. Wildcards are accepted. Empty to allow any domains")), '$force_publish' => array('publish_all', t("Force publish"), get_config('system','publish_all'), t("Check to force all profiles on this site to be listed in the site directory")), '$disable_discover_tab' => array('disable_discover_tab', t('Enable public stream'), $discover_tab, t('Enable the public stream. Warning: this content is unmoderated')), - '$site_firehose' => array('site_firehose', t('Site only public stream'), get_config('system','site_firehose'), t('Restrict the public stream to content origianting from this site')), + '$site_firehose' => array('site_firehose', t('Site only public stream'), get_config('system','site_firehose'), t('Restrict the public stream to content originating at this site')), '$open_pubstream' => array('open_pubstream', t('Allow anybody on the internet to access the public streams'), get_config('system','open_pubstream',1), t('Disable to require authentication before viewing')), '$incl' => array('pub_incl',t('Only import Public stream posts with this text'), get_config('system','pubstream_incl'),t('words one per line or #tags or /patterns/ or lang=xx, leave blank to import all posts')), '$excl' => array('pub_excl',t('Do not import Public stream posts with this text'), get_config('system','pubstream_excl'),t('words one per line or #tags or /patterns/ or lang=xx, leave blank to import all posts')), -- cgit v1.2.3 From 9f8585914c59117a41cd232435bc1e592ebdc0f1 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 7 Dec 2022 14:07:31 +0000 Subject: sse_bs: respect the site firehose setting --- Zotlabs/Module/Sse_bs.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Sse_bs.php b/Zotlabs/Module/Sse_bs.php index 4aabcafcb..ca9630c02 100644 --- a/Zotlabs/Module/Sse_bs.php +++ b/Zotlabs/Module/Sse_bs.php @@ -421,13 +421,19 @@ 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 . ") "; + $uids = " AND uid IN ( " . $sys['channel_id'] . " ) "; + + $site_firehose = get_config('system', 'site_firehose', 0); + if($site_firehose) { + $uids = " AND uid IN ( " . stream_perms_api_uids(PERMS_PUBLIC) . " ) AND item_private = 0 AND item_wall = 1 "; + } + $item_normal = item_normal(); if ($notifications) { $items = q("SELECT * FROM item - WHERE uid = %d + WHERE true $uids AND created <= '%s' - AND item_unseen = 1 AND obj_type NOT IN ('Document', 'Video', 'Audio', 'Image') AND author_xchan != '%s' AND created > '%s' @@ -435,7 +441,6 @@ class Sse_bs extends Controller { $sql_extra $sql_extra2 ORDER BY created DESC LIMIT $limit OFFSET $offset", - intval($sys['channel_id']), dbescdate($_SESSION['sse_loadtime']), dbesc(self::$ob_hash), dbescdate($_SESSION['static_loadtime']) @@ -454,17 +459,14 @@ class Sse_bs extends Controller { else { $result['pubs']['offset'] = -1; } - - } $r = q("SELECT id FROM item - WHERE uid = %d AND item_unseen = 1 + WHERE true $uids AND created > '%s' $item_normal $sql_extra AND author_xchan != '%s' LIMIT 100", - intval($sys['channel_id']), dbescdate($_SESSION['static_loadtime']), dbesc(self::$ob_hash) ); -- cgit v1.2.3 From 5c6d3753efc5b2534dbfd69a43c30d05bfc9096b Mon Sep 17 00:00:00 2001 From: Max Kostikov Date: Fri, 9 Dec 2022 15:53:01 +0000 Subject: Fix Redis session PHP warnings --- Zotlabs/Web/SessionRedis.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Web/SessionRedis.php b/Zotlabs/Web/SessionRedis.php index 66eb7a02d..f32e6a4f4 100644 --- a/Zotlabs/Web/SessionRedis.php +++ b/Zotlabs/Web/SessionRedis.php @@ -42,7 +42,7 @@ class SessionRedis implements \SessionHandlerInterface { } } - + #[\ReturnTypeWillChange] function open($s, $n) { return true; @@ -53,6 +53,7 @@ class SessionRedis implements \SessionHandlerInterface { // some which call read explicitly and some that do not. So we call it explicitly // just after sid regeneration to force a record to exist. + #[\ReturnTypeWillChange] function read($id) { if ($id) { @@ -67,7 +68,7 @@ class SessionRedis implements \SessionHandlerInterface { return ''; } - + #[\ReturnTypeWillChange] function write($id, $data) { // Pretend everything is hunky-dory, even though it isn't. @@ -100,13 +101,13 @@ class SessionRedis implements \SessionHandlerInterface { return true; } - + #[\ReturnTypeWillChange] function close() { return true; } - + #[\ReturnTypeWillChange] function destroy ($id) { $this->redis->del($id); @@ -114,7 +115,7 @@ class SessionRedis implements \SessionHandlerInterface { return true; } - + #[\ReturnTypeWillChange] function gc($expire) { return true; -- cgit v1.2.3 From e1c28351734d175476bc8f0d6cdf261dee3c07e0 Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 10 Dec 2022 17:03:57 +0000 Subject: add option to set worker sleep based on load average, remove redundand code and add return to some daemons --- Zotlabs/Daemon/Addon.php | 1 + Zotlabs/Daemon/Cache_embeds.php | 4 +++- Zotlabs/Daemon/Cache_query.php | 4 +++- Zotlabs/Daemon/Cli_suggest.php | 1 + Zotlabs/Daemon/Convo.php | 31 +++++++++++++++++++------------ Zotlabs/Daemon/Cron_daily.php | 2 ++ Zotlabs/Daemon/Cron_weekly.php | 11 ++++++----- Zotlabs/Daemon/Deliver.php | 2 ++ Zotlabs/Daemon/Deliver_hooks.php | 6 +++++- Zotlabs/Daemon/Directory.php | 2 ++ Zotlabs/Daemon/Expire.php | 2 ++ Zotlabs/Daemon/Importdoc.php | 2 ++ Zotlabs/Daemon/Master.php | 1 + Zotlabs/Daemon/Queue.php | 2 ++ Zotlabs/Daemon/Thumbnail.php | 2 ++ Zotlabs/Lib/QueueWorker.php | 26 +++++++++++++++++++------- 16 files changed, 72 insertions(+), 27 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Addon.php b/Zotlabs/Daemon/Addon.php index c6778750d..126e11cf6 100644 --- a/Zotlabs/Daemon/Addon.php +++ b/Zotlabs/Daemon/Addon.php @@ -7,6 +7,7 @@ class Addon { static public function run($argc, $argv) { call_hooks('daemon_addon', $argv); + return; } diff --git a/Zotlabs/Daemon/Cache_embeds.php b/Zotlabs/Daemon/Cache_embeds.php index 9e5b8d2bb..d5adfcc59 100644 --- a/Zotlabs/Daemon/Cache_embeds.php +++ b/Zotlabs/Daemon/Cache_embeds.php @@ -19,8 +19,10 @@ class Cache_embeds { $item = $c[0]; // bbcode conversion by default processes embeds that aren't already cached. - // Ignore the returned html output. + // Ignore the returned html output. bbcode($item['body']); + + return; } } diff --git a/Zotlabs/Daemon/Cache_query.php b/Zotlabs/Daemon/Cache_query.php index 5f92ae6d0..cd9597e9a 100644 --- a/Zotlabs/Daemon/Cache_query.php +++ b/Zotlabs/Daemon/Cache_query.php @@ -24,7 +24,7 @@ class Cache_query { array_shift($argv); array_shift($argv); - + $arr = json_decode(base64_decode($argv[0]), true); $r = call_user_func_array('q', $arr); @@ -32,5 +32,7 @@ class Cache_query { Cache::set($key, serialize($r)); del_config('procid', $key); + + return; } } diff --git a/Zotlabs/Daemon/Cli_suggest.php b/Zotlabs/Daemon/Cli_suggest.php index 5dced462d..6306d2113 100644 --- a/Zotlabs/Daemon/Cli_suggest.php +++ b/Zotlabs/Daemon/Cli_suggest.php @@ -9,6 +9,7 @@ class Cli_suggest { static public function run($argc,$argv) { update_suggestions(); + return: } } diff --git a/Zotlabs/Daemon/Convo.php b/Zotlabs/Daemon/Convo.php index 940216b2c..d1a7e4f4d 100644 --- a/Zotlabs/Daemon/Convo.php +++ b/Zotlabs/Daemon/Convo.php @@ -30,6 +30,7 @@ class Convo { intval($channel_id), dbesc($contact_hash) ); + if (!$r) { return; } @@ -40,19 +41,25 @@ class Convo { $messages = $obj->get(); - if ($messages) { - foreach ($messages as $message) { - if (is_string($message)) { - $message = Activity::fetch($message, $channel); - } - // set client flag because comments will probably just be objects and not full blown activities - // and that lets us use implied_create - $AS = new ActivityStreams($message); - if ($AS->is_valid() && is_array($AS->obj)) { - $item = Activity::decode_note($AS); - Activity::store($channel, $contact['abook_xchan'], $AS, $item); - } + if (!$messages) { + return; + } + + foreach ($messages as $message) { + if (is_string($message)) { + $message = Activity::fetch($message, $channel); + } + + // set client flag because comments will probably just be objects and not full blown activities + // and that lets us use implied_create + $AS = new ActivityStreams($message); + if ($AS->is_valid() && is_array($AS->obj)) { + $item = Activity::decode_note($AS); + Activity::store($channel, $contact['abook_xchan'], $AS, $item); } } + + return; + } } diff --git a/Zotlabs/Daemon/Cron_daily.php b/Zotlabs/Daemon/Cron_daily.php index 71d3bc9ef..6d62836c7 100644 --- a/Zotlabs/Daemon/Cron_daily.php +++ b/Zotlabs/Daemon/Cron_daily.php @@ -119,5 +119,7 @@ class Cron_daily { /** * End Cron Daily */ + + return; } } diff --git a/Zotlabs/Daemon/Cron_weekly.php b/Zotlabs/Daemon/Cron_weekly.php index 407aa40ef..75fb94700 100644 --- a/Zotlabs/Daemon/Cron_weekly.php +++ b/Zotlabs/Daemon/Cron_weekly.php @@ -22,12 +22,12 @@ class Cron_weekly { mark_orphan_hubsxchans(); - // Find channels that were removed in the last three weeks, but + // Find channels that were removed in the last three weeks, but // haven't been finally cleaned up. These should be older than 10 - // days to ensure that "purgeall" messages have gone out or bounced - // or timed out. + // days to ensure that "purgeall" messages have gone out or bounced + // or timed out. - $r = q("select channel_id from channel where channel_removed = 1 and + $r = q("select channel_id from channel where channel_removed = 1 and channel_deleted > %s - INTERVAL %s and channel_deleted < %s - INTERVAL %s", db_utcnow(), db_quoteinterval('21 DAY'), db_utcnow(), db_quoteinterval('10 DAY') @@ -59,5 +59,6 @@ class Cron_weekly { * End Cron Weekly */ + return; } -} \ No newline at end of file +} diff --git a/Zotlabs/Daemon/Deliver.php b/Zotlabs/Daemon/Deliver.php index 400ef697b..2d80dc093 100644 --- a/Zotlabs/Daemon/Deliver.php +++ b/Zotlabs/Daemon/Deliver.php @@ -28,6 +28,8 @@ class Deliver { } + return; + } } diff --git a/Zotlabs/Daemon/Deliver_hooks.php b/Zotlabs/Daemon/Deliver_hooks.php index 4d3ce4e1d..1e478db1e 100644 --- a/Zotlabs/Daemon/Deliver_hooks.php +++ b/Zotlabs/Daemon/Deliver_hooks.php @@ -12,8 +12,12 @@ class Deliver_hooks { $r = q("select * from item where id = '%d'", intval($argv[1]) ); - if ($r) + + if ($r) { call_hooks('notifier_normal', $r[0]); + } + + return; } } diff --git a/Zotlabs/Daemon/Directory.php b/Zotlabs/Daemon/Directory.php index 3996b8079..19adf8273 100644 --- a/Zotlabs/Daemon/Directory.php +++ b/Zotlabs/Daemon/Directory.php @@ -97,5 +97,7 @@ class Directory { if ($pushall) { Master::Summon(array('Notifier', 'refresh_all', $channel['channel_id'])); } + + return; } } diff --git a/Zotlabs/Daemon/Expire.php b/Zotlabs/Daemon/Expire.php index 99fe68b6f..5d9f14b28 100644 --- a/Zotlabs/Daemon/Expire.php +++ b/Zotlabs/Daemon/Expire.php @@ -103,5 +103,7 @@ class Expire { } del_config('procid', 'expire'); + + return; } } diff --git a/Zotlabs/Daemon/Importdoc.php b/Zotlabs/Daemon/Importdoc.php index 9e818e2b3..c5a81e50c 100644 --- a/Zotlabs/Daemon/Importdoc.php +++ b/Zotlabs/Daemon/Importdoc.php @@ -11,6 +11,8 @@ class Importdoc { self::update_docs_dir('doc/*'); + return; + } static public function update_docs_dir($s) { diff --git a/Zotlabs/Daemon/Master.php b/Zotlabs/Daemon/Master.php index 495718bf4..c9ed91aaa 100644 --- a/Zotlabs/Daemon/Master.php +++ b/Zotlabs/Daemon/Master.php @@ -11,6 +11,7 @@ if (array_search(__file__, get_included_files()) === 0) { if ($argc) Master::Release($argc, $argv); + return; } diff --git a/Zotlabs/Daemon/Queue.php b/Zotlabs/Daemon/Queue.php index 41aaf45ed..3eb7d9d23 100644 --- a/Zotlabs/Daemon/Queue.php +++ b/Zotlabs/Daemon/Queue.php @@ -79,5 +79,7 @@ class Queue { foreach ($r as $rv) { LibQueue::deliver($rv); } + + return; } } diff --git a/Zotlabs/Daemon/Thumbnail.php b/Zotlabs/Daemon/Thumbnail.php index 3688e8ae5..fa9570658 100644 --- a/Zotlabs/Daemon/Thumbnail.php +++ b/Zotlabs/Daemon/Thumbnail.php @@ -73,5 +73,7 @@ class Thumbnail { || (filectime(dbunescbin($attach['content']) . 'thumb') < (time() - 60)))) { $default_controller->Thumb($attach, $preview_style, $preview_width, $preview_height); } + + return; } } diff --git a/Zotlabs/Lib/QueueWorker.php b/Zotlabs/Lib/QueueWorker.php index 21983a4e2..48d5f5bb2 100644 --- a/Zotlabs/Lib/QueueWorker.php +++ b/Zotlabs/Lib/QueueWorker.php @@ -231,9 +231,6 @@ class QueueWorker { } public static function Process() { - self::$workersleep = get_config('queueworker', 'queue_worker_sleep'); - self::$workersleep = intval(self::$workersleep) > 100 ? intval(self::$workersleep) : 100; - if (!self::GetWorkerID()) { logger('Unable to get worker ID. Exiting.', LOGGER_DEBUG); killme(); @@ -241,11 +238,26 @@ class QueueWorker { $jobs = 0; $workid = self::getWorkId(); + $load_average_sleep = false; + self::$workersleep = get_config('queueworker', 'queue_worker_sleep'); + self::$workersleep = ((intval(self::$workersleep) > 100) ? intval(self::$workersleep) : 100); + + if (function_exists('sys_getloadavg') && get_config('queueworker', 'load_average_sleep')) { + $load_average_sleep = true; + } + while ($workid) { + + if ($load_average_sleep) { + $load_average = sys_getloadavg(); + self::$workersleep = intval($load_average[0]) * 100000; + + if (!self::$workersleep) { + self::$workersleep = 100; + } + } + usleep(self::$workersleep); - // @FIXME: Currently $workersleep is a fixed value. It may be a good idea - // to implement a "backoff" instead - based on load average or some - // other metric. self::qbegin('workerq'); @@ -276,7 +288,7 @@ class QueueWorker { $workinfo = json_decode($workitem[0]['workerq_data'], true); $argv = $workinfo['argv']; - logger('Master: process: ' . json_encode($argv), LOGGER_DEBUG); + hz_syslog('Master: process: ' . json_encode($argv), LOGGER_DEBUG); $cls = '\\Zotlabs\\Daemon\\' . $argv[0]; $argv = flatten_array_recursive($argv); -- cgit v1.2.3 From 86e1dd4673017ecc3f595ecfa6c9e257b86878ac Mon Sep 17 00:00:00 2001 From: Mario Date: Sat, 10 Dec 2022 17:06:54 +0000 Subject: remove debug logging --- Zotlabs/Lib/QueueWorker.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/QueueWorker.php b/Zotlabs/Lib/QueueWorker.php index 48d5f5bb2..ff29fa065 100644 --- a/Zotlabs/Lib/QueueWorker.php +++ b/Zotlabs/Lib/QueueWorker.php @@ -288,7 +288,7 @@ class QueueWorker { $workinfo = json_decode($workitem[0]['workerq_data'], true); $argv = $workinfo['argv']; - hz_syslog('Master: process: ' . json_encode($argv), LOGGER_DEBUG); + logger('Master: process: ' . json_encode($argv), LOGGER_DEBUG); $cls = '\\Zotlabs\\Daemon\\' . $argv[0]; $argv = flatten_array_recursive($argv); -- cgit v1.2.3 From 1c17768dc5a4de21d8b431807fd184101c1d2c58 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 11 Dec 2022 10:40:02 +0000 Subject: minor fixes --- Zotlabs/Lib/QueueWorker.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/QueueWorker.php b/Zotlabs/Lib/QueueWorker.php index ff29fa065..9f60e3315 100644 --- a/Zotlabs/Lib/QueueWorker.php +++ b/Zotlabs/Lib/QueueWorker.php @@ -68,8 +68,6 @@ class QueueWorker { public static function Summon(&$argv) { - $argc = count($argv); - if ($argv[0] !== 'Queueworker') { $priority = 0; // @TODO allow reprioritization @@ -78,7 +76,7 @@ class QueueWorker { $priority = self::$default_priorities[$argv[0]]; } - $workinfo = ['argc' => $argc, 'argv' => $argv]; + $workinfo = ['argc' => count($argv), 'argv' => $argv]; $workinfo_json = json_encode($workinfo); $uuid = self::getUuid($workinfo_json); @@ -118,8 +116,6 @@ class QueueWorker { public static function Release(&$argv) { - $argc = count($argv); - if ($argv[0] !== 'Queueworker') { $priority = 0; // @TODO allow reprioritization @@ -127,7 +123,7 @@ class QueueWorker { $priority = self::$default_priorities[$argv[0]]; } - $workinfo = ['argc' => $argc, 'argv' => $argv]; + $workinfo = ['argc' => count($argv), 'argv' => $argv]; $workinfo_json = json_encode($workinfo); $uuid = self::getUuid($workinfo_json); @@ -250,7 +246,7 @@ class QueueWorker { if ($load_average_sleep) { $load_average = sys_getloadavg(); - self::$workersleep = intval($load_average[0]) * 100000; + self::$workersleep = intval($load_average[0]) * 10000; if (!self::$workersleep) { self::$workersleep = 100; @@ -288,7 +284,6 @@ class QueueWorker { $workinfo = json_decode($workitem[0]['workerq_data'], true); $argv = $workinfo['argv']; - logger('Master: process: ' . json_encode($argv), LOGGER_DEBUG); $cls = '\\Zotlabs\\Daemon\\' . $argv[0]; $argv = flatten_array_recursive($argv); -- cgit v1.2.3 From 7ef0b05ce68a24f3f0d98de5018a2ee64520b168 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 11 Dec 2022 20:24:22 +0000 Subject: fix typo --- Zotlabs/Daemon/Cli_suggest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Cli_suggest.php b/Zotlabs/Daemon/Cli_suggest.php index 6306d2113..028228cb0 100644 --- a/Zotlabs/Daemon/Cli_suggest.php +++ b/Zotlabs/Daemon/Cli_suggest.php @@ -9,7 +9,7 @@ class Cli_suggest { static public function run($argc,$argv) { update_suggestions(); - return: + return; } } -- cgit v1.2.3 From 45f8e43be425b9718aa9ac819256ea407af900f0 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 11 Dec 2022 20:46:02 +0000 Subject: debug from php log --- Zotlabs/Lib/Libzot.php | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/Libzot.php b/Zotlabs/Lib/Libzot.php index b0d33e055..c635fdb17 100644 --- a/Zotlabs/Lib/Libzot.php +++ b/Zotlabs/Lib/Libzot.php @@ -291,6 +291,12 @@ class Libzot { } $m = parse_url($url); + + if (!$m) { + logger('zot_refresh: could not parse url'); + return false; + } + $site_url = unparse_url([ 'scheme' => $m['scheme'], 'host' => $m['host'] ]); $s = q("select site_dead from site where site_url = '%s' limit 1", -- cgit v1.2.3 From e3a19469eb6940249ad87662399d14dbf2a79847 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 12 Dec 2022 09:03:49 +0000 Subject: bring back poll and delivery interval --- Zotlabs/Daemon/Cron.php | 20 ++++++++++---------- Zotlabs/Daemon/Poller.php | 24 +++++++++++------------- Zotlabs/Lib/Libsync.php | 9 +++++---- Zotlabs/Module/Admin/Site.php | 12 ++++++------ Zotlabs/Widget/Messages.php | 7 ++++--- 5 files changed, 36 insertions(+), 36 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Cron.php b/Zotlabs/Daemon/Cron.php index 9b8946e57..b8bcbe3a2 100644 --- a/Zotlabs/Daemon/Cron.php +++ b/Zotlabs/Daemon/Cron.php @@ -52,7 +52,7 @@ class Cron { require_once('include/account.php'); remove_expired_registrations(); - //$interval = get_config('system', 'delivery_interval', 3); + $interval = get_config('system', 'delivery_interval', 3); // expire any expired items @@ -67,10 +67,10 @@ class Cron { if ($rr['item_wall']) { // The notifier isn't normally invoked unless item_drop is interactive. Master::Summon(['Notifier', 'drop', $rr['id']]); - /* - if ($interval) + + if ($interval) { @time_sleep_until(microtime(true) + (float)$interval); - */ + } } } } @@ -100,10 +100,10 @@ class Cron { if ($r) { foreach ($r as $rr) { Master::Summon(array('Directory', $rr['channel_id'], 'force')); - /* - if ($interval) + + if ($interval) { @time_sleep_until(microtime(true) + (float)$interval); - */ + } } } @@ -157,10 +157,10 @@ class Cron { ); } Master::Summon(array('Notifier', 'wall-new', $rr['id'])); - /* - if ($interval) + + if ($interval) { @time_sleep_until(microtime(true) + (float)$interval); - */ + } } } } diff --git a/Zotlabs/Daemon/Poller.php b/Zotlabs/Daemon/Poller.php index 5bf8d3a02..b43b814f7 100644 --- a/Zotlabs/Daemon/Poller.php +++ b/Zotlabs/Daemon/Poller.php @@ -17,12 +17,13 @@ class Poller { } } -/* + $interval = intval(get_config('system', 'poll_interval')); - if (!$interval) + if (!$interval) { $interval = ((get_config('system', 'delivery_interval') === false) ? 3 : intval(get_config('system', 'delivery_interval'))); + } - +/* // Check for a lockfile. If it exists, but is over an hour old, it's stale. Ignore it. $lockfile = 'store/[data]/poller'; if ((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600)) @@ -106,10 +107,10 @@ class Poller { if ($t < $x) { Master::Summon(['Onepoll', $contact['abook_id']]); - /* - if ($interval) + + if ($interval) { @time_sleep_until(microtime(true) + (float)$interval); - */ + } } continue; @@ -173,11 +174,9 @@ class Poller { Master::Summon(['Onepoll', $contact['abook_id']]); - /* - if ($interval) + if ($interval) { @time_sleep_until(microtime(true) + (float)$interval); - */ - + } } } @@ -201,10 +200,9 @@ class Poller { Master::Summon(['Onedirsync', $rr['ud_id']]); - /* - if ($interval) + if ($interval) { @time_sleep_until(microtime(true) + (float)$interval); - */ + } } } } diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php index b02ae4c69..2d6d86d78 100644 --- a/Zotlabs/Lib/Libsync.php +++ b/Zotlabs/Lib/Libsync.php @@ -135,10 +135,9 @@ class Libsync { $info['collection_members'] = $r; } - /* + $interval = ((get_config('system', 'delivery_interval') !== false) ? intval(get_config('system', 'delivery_interval')) : 2); - */ logger('Packet: ' . print_r($info, true), LOGGER_DATA, LOG_DEBUG); @@ -171,10 +170,12 @@ class Libsync { /* $total = $total - 1; + */ - if ($interval && $total) + if ($interval) { @time_sleep_until(microtime(true) + (float)$interval); - */ + } + } } diff --git a/Zotlabs/Module/Admin/Site.php b/Zotlabs/Module/Admin/Site.php index e3feee1bb..42cf064c9 100644 --- a/Zotlabs/Module/Admin/Site.php +++ b/Zotlabs/Module/Admin/Site.php @@ -83,9 +83,9 @@ class Site { $proxyuser = ((x($_POST,'proxyuser')) ? notags(trim($_POST['proxyuser'])) : ''); $proxy = ((x($_POST,'proxy')) ? notags(trim($_POST['proxy'])) : ''); $timeout = ((x($_POST,'timeout')) ? intval(trim($_POST['timeout'])) : 60); - //$delivery_interval = ((x($_POST,'delivery_interval'))? intval(trim($_POST['delivery_interval'])) : 0); + $delivery_interval = ((x($_POST,'delivery_interval'))? intval(trim($_POST['delivery_interval'])) : 0); $delivery_batch_count = ((x($_POST,'delivery_batch_count') && $_POST['delivery_batch_count'] > 0)? intval(trim($_POST['delivery_batch_count'])) : 1); - //$poll_interval = ((x($_POST,'poll_interval')) ? intval(trim($_POST['poll_interval'])) : 0); + $poll_interval = ((x($_POST,'poll_interval')) ? intval(trim($_POST['poll_interval'])) : 0); $maxloadavg = ((x($_POST,'maxloadavg')) ? intval(trim($_POST['maxloadavg'])) : 50); $feed_contacts = ((x($_POST,'feed_contacts')) ? intval($_POST['feed_contacts']) : 0); $verify_email = ((x($_POST,'verify_email')) ? 1 : 0); @@ -136,9 +136,9 @@ class Site { // <-hilmar] set_config('system', 'feed_contacts', $feed_contacts); - //set_config('system', 'delivery_interval', $delivery_interval); + set_config('system', 'delivery_interval', $delivery_interval); set_config('system', 'delivery_batch_count', $delivery_batch_count); - //set_config('system', 'poll_interval', $poll_interval); + set_config('system', 'poll_interval', $poll_interval); set_config('system', 'maxloadavg', $maxloadavg); set_config('system', 'frontpage', $frontpage); set_config('system', 'sellpage', $site_sellpage); @@ -530,10 +530,10 @@ class Site { '$proxyuser' => array('proxyuser', t("Proxy user"), get_config('system','proxyuser'), ""), '$proxy' => array('proxy', t("Proxy URL"), get_config('system','proxy'), ""), '$timeout' => array('timeout', t("Network timeout"), (x(get_config('system','curl_timeout'))?get_config('system','curl_timeout'):60), t("Value is in seconds. Set to 0 for unlimited (not recommended).")), - //'$delivery_interval' => array('delivery_interval', t("Delivery interval"), (x(get_config('system','delivery_interval'))?get_config('system','delivery_interval'):2), t("Delay background delivery processes by this many seconds to reduce system load. Recommend: 4-5 for shared hosts, 2-3 for virtual private servers. 0-1 for large dedicated servers.")), + '$delivery_interval' => array('delivery_interval', t("Delivery interval"), (x(get_config('system','delivery_interval'))?get_config('system','delivery_interval'):2), t("Delay background delivery processes by this many seconds to reduce system load. Recommend: 4-5 for shared hosts, 2-3 for virtual private servers. 0-1 for large dedicated servers.")), '$delivery_batch_count' => array('delivery_batch_count', t('Deliveries per process'),(x(get_config('system','delivery_batch_count'))?get_config('system','delivery_batch_count'):1), t("Number of deliveries to attempt in a single operating system process. Adjust if necessary to tune system performance. Recommend: 1-5.")), //'$force_queue' => array('force_queue', t("Queue Threshold"), get_config('system','force_queue_threshold',3000), t("Always defer immediate delivery if queue contains more than this number of entries.")), - //'$poll_interval' => array('poll_interval', t("Poll interval"), (x(get_config('system','poll_interval'))?get_config('system','poll_interval'):2), t("Delay background polling processes by this many seconds to reduce system load. If 0, use delivery interval.")), + '$poll_interval' => array('poll_interval', t("Poll interval"), (x(get_config('system','poll_interval'))?get_config('system','poll_interval'):2), t("Delay background polling processes by this many seconds to reduce system load. If 0, use delivery interval.")), '$imagick_path' => array('imagick_path', t("Path to ImageMagick convert program"), get_config('system','imagick_convert_path'), t("If set, use this program to generate photo thumbnails for huge images ( > 4000 pixels in either dimension), otherwise memory exhaustion may occur. Example: /usr/bin/convert")), '$maxloadavg' => array('maxloadavg', t("Maximum Load Average"), ((intval(get_config('system','maxloadavg')) > 0)?get_config('system','maxloadavg'):50), t("Maximum system load before delivery and poll processes are deferred - default 50.")), '$default_expire_days' => array('default_expire_days', t('Expiration period in days for imported (grid/network) content'), intval(get_config('system','default_expire_days')), t('0 for no expiration of imported content')), diff --git a/Zotlabs/Widget/Messages.php b/Zotlabs/Widget/Messages.php index 0f57a8d85..9a3f0fa9c 100644 --- a/Zotlabs/Widget/Messages.php +++ b/Zotlabs/Widget/Messages.php @@ -58,7 +58,8 @@ class Messages { } $channel = App::get_channel(); - $item_normal = str_replace('item.', 'i.', item_normal()); + $item_normal_i = str_replace('item.', 'i.', item_normal()); + $item_normal_c = str_replace('item.', 'c.', item_normal()); $entries = []; $limit = 30; $dummy_order_sql = ''; @@ -89,12 +90,12 @@ class Messages { } $items = q("SELECT *, - (SELECT count(*) FROM item c WHERE c.uid = %d AND c.parent = i.parent AND c.item_unseen = 1 AND c.item_thread_top = 0 $vnotify_sql) AS unseen_count + (SELECT count(*) FROM item c WHERE c.uid = %d AND c.parent = i.parent AND c.item_unseen = 1 AND c.item_thread_top = 0 $item_normal_c $vnotify_sql) AS unseen_count FROM item i WHERE i.uid = %d AND i.created <= '%s' $type_sql AND i.item_thread_top = 1 - $item_normal + $item_normal_i ORDER BY i.created DESC $dummy_order_sql LIMIT $limit OFFSET $offset", intval(local_channel()), -- cgit v1.2.3 From c9e170dfcc83a946fda7d4335c136ed40b3c579d Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Mon, 12 Dec 2022 23:26:45 +0100 Subject: queueworker: introduce new interval config queueworker.queue_interval - defaults to 500000 microseconds. No config UI yet. --- Zotlabs/Daemon/Cron.php | 8 ++++---- Zotlabs/Daemon/Poller.php | 10 +++++----- Zotlabs/Lib/Libsync.php | 6 ++---- Zotlabs/Lib/QueueWorker.php | 13 ++++++------- 4 files changed, 17 insertions(+), 20 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Cron.php b/Zotlabs/Daemon/Cron.php index b8bcbe3a2..640f06102 100644 --- a/Zotlabs/Daemon/Cron.php +++ b/Zotlabs/Daemon/Cron.php @@ -52,7 +52,7 @@ class Cron { require_once('include/account.php'); remove_expired_registrations(); - $interval = get_config('system', 'delivery_interval', 3); + $interval = get_config('queueworker', 'queue_interval', 500000); // expire any expired items @@ -69,7 +69,7 @@ class Cron { Master::Summon(['Notifier', 'drop', $rr['id']]); if ($interval) { - @time_sleep_until(microtime(true) + (float)$interval); + usleep($interval); } } } @@ -102,7 +102,7 @@ class Cron { Master::Summon(array('Directory', $rr['channel_id'], 'force')); if ($interval) { - @time_sleep_until(microtime(true) + (float)$interval); + usleep($interval); } } } @@ -159,7 +159,7 @@ class Cron { Master::Summon(array('Notifier', 'wall-new', $rr['id'])); if ($interval) { - @time_sleep_until(microtime(true) + (float)$interval); + usleep($interval); } } } diff --git a/Zotlabs/Daemon/Poller.php b/Zotlabs/Daemon/Poller.php index b43b814f7..0fdc3da16 100644 --- a/Zotlabs/Daemon/Poller.php +++ b/Zotlabs/Daemon/Poller.php @@ -17,13 +17,13 @@ class Poller { } } + $interval = get_config('queueworker', 'queue_interval', 500000); - $interval = intval(get_config('system', 'poll_interval')); +/* if (!$interval) { $interval = ((get_config('system', 'delivery_interval') === false) ? 3 : intval(get_config('system', 'delivery_interval'))); } -/* // Check for a lockfile. If it exists, but is over an hour old, it's stale. Ignore it. $lockfile = 'store/[data]/poller'; if ((file_exists($lockfile)) && (filemtime($lockfile) > (time() - 3600)) @@ -109,7 +109,7 @@ class Poller { Master::Summon(['Onepoll', $contact['abook_id']]); if ($interval) { - @time_sleep_until(microtime(true) + (float)$interval); + usleep($interval); } } @@ -175,7 +175,7 @@ class Poller { Master::Summon(['Onepoll', $contact['abook_id']]); if ($interval) { - @time_sleep_until(microtime(true) + (float)$interval); + usleep($interval); } } } @@ -201,7 +201,7 @@ class Poller { Master::Summon(['Onedirsync', $rr['ud_id']]); if ($interval) { - @time_sleep_until(microtime(true) + (float)$interval); + usleep($interval); } } } diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php index 2d6d86d78..f844c63b5 100644 --- a/Zotlabs/Lib/Libsync.php +++ b/Zotlabs/Lib/Libsync.php @@ -135,9 +135,7 @@ class Libsync { $info['collection_members'] = $r; } - - $interval = ((get_config('system', 'delivery_interval') !== false) - ? intval(get_config('system', 'delivery_interval')) : 2); + $interval = get_config('queueworker', 'queue_interval', 500000); logger('Packet: ' . print_r($info, true), LOGGER_DATA, LOG_DEBUG); @@ -173,7 +171,7 @@ class Libsync { */ if ($interval) { - @time_sleep_until(microtime(true) + (float)$interval); + usleep($interval); } } diff --git a/Zotlabs/Lib/QueueWorker.php b/Zotlabs/Lib/QueueWorker.php index 9f60e3315..468383ae2 100644 --- a/Zotlabs/Lib/QueueWorker.php +++ b/Zotlabs/Lib/QueueWorker.php @@ -66,7 +66,7 @@ class QueueWorker { return; } - public static function Summon(&$argv) { + public static function Summon($argv) { if ($argv[0] !== 'Queueworker') { @@ -102,19 +102,18 @@ class QueueWorker { return; } self::qcommit(); - logger('INSERTED: ' . $workinfo_json, LOGGER_DEBUG); + hz_syslog('INSERTED: ' . $workinfo_json, LOGGER_DEBUG); } - $argv = []; $workers = self::GetWorkerCount(); if ($workers < self::$maxworkers) { - logger("Less than max active workers ($workers) max = " . self::$maxworkers . ".", LOGGER_DEBUG); + hz_syslog("Less than max active workers ($workers) max = " . self::$maxworkers . ".", LOGGER_DEBUG); $phpbin = get_config('system', 'phpbin', 'php'); proc_run($phpbin, 'Zotlabs/Daemon/Master.php', ['Queueworker']); } } - public static function Release(&$argv) { + public static function Release($argv) { if ($argv[0] !== 'Queueworker') { @@ -152,7 +151,7 @@ class QueueWorker { self::qcommit(); logger('INSERTED: ' . $workinfo_json, LOGGER_DEBUG); } - $argv = []; + self::Process(); } @@ -228,7 +227,7 @@ class QueueWorker { public static function Process() { if (!self::GetWorkerID()) { - logger('Unable to get worker ID. Exiting.', LOGGER_DEBUG); + hz_syslog('Unable to get worker ID. Exiting.', LOGGER_DEBUG); killme(); } -- cgit v1.2.3 From 2f687de477c3aeec7ee684fd875e5190ae4c2fbe Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 15 Dec 2022 09:18:58 +0000 Subject: queueworker testing and more logging to syslog --- Zotlabs/Daemon/Externals.php | 2 +- Zotlabs/Lib/QueueWorker.php | 37 ++++++++++++++++++++++--------------- 2 files changed, 23 insertions(+), 16 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Externals.php b/Zotlabs/Daemon/Externals.php index 91fa09044..2c7c7c172 100644 --- a/Zotlabs/Daemon/Externals.php +++ b/Zotlabs/Daemon/Externals.php @@ -143,7 +143,7 @@ class Externals { $AS = new ActivityStreams($message); if ($AS->is_valid() && is_array($AS->obj)) { $item = Activity::decode_note($AS); - Activity::store($importer, $contact['abook_xchan'], $AS, $item); + Activity::store($importer, $contact['hubloc_hash'], $AS, $item); $total++; } } diff --git a/Zotlabs/Lib/QueueWorker.php b/Zotlabs/Lib/QueueWorker.php index 468383ae2..b4ee6c327 100644 --- a/Zotlabs/Lib/QueueWorker.php +++ b/Zotlabs/Lib/QueueWorker.php @@ -27,7 +27,7 @@ class QueueWorker { switch (ACTIVE_DBTYPE) { case DBTYPE_MYSQL: q('BEGIN'); - q('LOCK TABLE ' . $tablename . ' WRITE'); + //q('LOCK TABLE ' . $tablename . ' WRITE'); break; case DBTYPE_POSTGRES: @@ -41,7 +41,7 @@ class QueueWorker { private static function qcommit() { switch (ACTIVE_DBTYPE) { case DBTYPE_MYSQL: - q("UNLOCK TABLES"); + //q("UNLOCK TABLES"); q("COMMIT"); break; @@ -56,7 +56,7 @@ class QueueWorker { switch (ACTIVE_DBTYPE) { case DBTYPE_MYSQL: q("ROLLBACK"); - q("UNLOCK TABLES"); + //q("UNLOCK TABLES"); break; case DBTYPE_POSTGRES: @@ -199,7 +199,7 @@ class QueueWorker { $work = dbq("SELECT workerq_id FROM workerq WHERE workerq_reservationid IS NULL ORDER BY workerq_priority DESC, workerq_id ASC LIMIT 1 FOR UPDATE SKIP LOCKED;"); } else { - $work = dbq("SELECT workerq_id FROM workerq WHERE workerq_reservationid IS NULL ORDER BY workerq_priority DESC, workerq_id ASC LIMIT 1;"); + $work = dbq("SELECT workerq_id FROM workerq WHERE workerq_reservationid IS NULL ORDER BY workerq_priority DESC, workerq_id ASC LIMIT 1 FOR UPDATE SKIP LOCKED;"); } if (!$work) { @@ -256,16 +256,18 @@ class QueueWorker { self::qbegin('workerq'); - if (ACTIVE_DBTYPE == DBTYPE_POSTGRES) { - $workitem = q("SELECT * FROM workerq WHERE workerq_id = %d FOR UPDATE SKIP LOCKED", - $workid - ); - } - else { - $workitem = q("SELECT * FROM workerq WHERE workerq_id = %d", - $workid - ); - } + //if (ACTIVE_DBTYPE == DBTYPE_POSTGRES) { + //$workitem = q("SELECT * FROM workerq WHERE workerq_id = %d FOR UPDATE SKIP LOCKED", + //$workid + //); + //} + //else { + //$workitem = q("SELECT * FROM workerq WHERE workerq_id = %d FOR UPDATE SKIP LOCKED", + //$workid + //); + //} + + $workitem = dbq("SELECT * FROM workerq WHERE workerq_id = $workid"); self::qcommit(); @@ -287,7 +289,12 @@ class QueueWorker { $cls = '\\Zotlabs\\Daemon\\' . $argv[0]; $argv = flatten_array_recursive($argv); $argc = count($argv); + + $rnd = random_string(); + + hz_syslog('PROCESSING: ' . $rnd . ' ' . print_r($argv,true)); $cls::run($argc, $argv); + hz_syslog('COMPLETED: ' . $rnd); // @FIXME: Right now we assume that if we get a return, everything is OK. // At some point we may want to test whether the run returns true/false @@ -295,7 +302,7 @@ class QueueWorker { // to implement some sort of "retry interval" first. self::qbegin('workerq'); - q("delete from workerq where workerq_id = %d", $workid); + dbq("delete from workerq where workerq_id = $workid"); self::qcommit(); } else { -- cgit v1.2.3 From 4d54755057047f6947285ee0db6e89fa12f294c8 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 15 Dec 2022 16:53:17 +0000 Subject: queueworker: fix maxworkers check and cleanup --- Zotlabs/Lib/QueueWorker.php | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/QueueWorker.php b/Zotlabs/Lib/QueueWorker.php index b4ee6c327..2bcbdfc5c 100644 --- a/Zotlabs/Lib/QueueWorker.php +++ b/Zotlabs/Lib/QueueWorker.php @@ -23,16 +23,14 @@ class QueueWorker { 'Directory' => 1 ]; - private static function qbegin($tablename) { + private static function qbegin() { switch (ACTIVE_DBTYPE) { case DBTYPE_MYSQL: q('BEGIN'); - //q('LOCK TABLE ' . $tablename . ' WRITE'); break; case DBTYPE_POSTGRES: q('BEGIN'); - //q('LOCK TABLE '.$tablename.' IN ACCESS EXCLUSIVE MODE'); break; } return; @@ -90,7 +88,7 @@ class QueueWorker { return; } - self::qbegin('workerq'); + self::qbegin(); $r = q("INSERT INTO workerq (workerq_priority, workerq_data, workerq_uuid) VALUES (%d, '%s', '%s')", intval($priority), $workinfo_json, @@ -106,8 +104,8 @@ class QueueWorker { } $workers = self::GetWorkerCount(); - if ($workers < self::$maxworkers) { - hz_syslog("Less than max active workers ($workers) max = " . self::$maxworkers . ".", LOGGER_DEBUG); + if ($workers <= self::$maxworkers) { + hz_syslog("Less <= max active workers ($workers) max = " . self::$maxworkers . ".", LOGGER_DEBUG); $phpbin = get_config('system', 'phpbin', 'php'); proc_run($phpbin, 'Zotlabs/Daemon/Master.php', ['Queueworker']); } @@ -137,7 +135,7 @@ class QueueWorker { return; } - self::qbegin('workerq'); + self::qbegin(); $r = q("INSERT INTO workerq (workerq_priority, workerq_data, workerq_uuid) VALUES (%d, '%s', '%s')", intval($priority), $workinfo_json, @@ -193,7 +191,7 @@ class QueueWorker { private static function getWorkId() { self::GetWorkerCount(); - self::qbegin('workerq'); + self::qbegin(); if (ACTIVE_DBTYPE == DBTYPE_POSTGRES) { $work = dbq("SELECT workerq_id FROM workerq WHERE workerq_reservationid IS NULL ORDER BY workerq_priority DESC, workerq_id ASC LIMIT 1 FOR UPDATE SKIP LOCKED;"); @@ -254,28 +252,15 @@ class QueueWorker { usleep(self::$workersleep); - self::qbegin('workerq'); - - //if (ACTIVE_DBTYPE == DBTYPE_POSTGRES) { - //$workitem = q("SELECT * FROM workerq WHERE workerq_id = %d FOR UPDATE SKIP LOCKED", - //$workid - //); - //} - //else { - //$workitem = q("SELECT * FROM workerq WHERE workerq_id = %d FOR UPDATE SKIP LOCKED", - //$workid - //); - //} - + self::qbegin(); $workitem = dbq("SELECT * FROM workerq WHERE workerq_id = $workid"); - self::qcommit(); if (isset($workitem[0])) { // At least SOME work to do.... in case there's more, let's ramp up workers. $workers = self::GetWorkerCount(); - if ($workers < self::$maxworkers) { - logger("Less than max active workers ($workers) max = " . self::$maxworkers . ".", LOGGER_DEBUG); + if ($workers <= self::$maxworkers) { + logger("Less <= max active workers ($workers) max = " . self::$maxworkers . ".", LOGGER_DEBUG); $phpbin = get_config('system', 'phpbin', 'php'); proc_run($phpbin, 'Zotlabs/Daemon/Master.php', ['Queueworker']); } @@ -301,7 +286,7 @@ class QueueWorker { // and requeue the work to be tried again if needed. But we probably want // to implement some sort of "retry interval" first. - self::qbegin('workerq'); + self::qbegin(); dbq("delete from workerq where workerq_id = $workid"); self::qcommit(); } -- cgit v1.2.3 From e36677b757f71ad105adebc73fb26dd449e7e620 Mon Sep 17 00:00:00 2001 From: Mario Date: Sun, 18 Dec 2022 10:19:06 +0000 Subject: queueworker: cleanup and implement auto sleep interval (hidden config for now) --- Zotlabs/Lib/QueueWorker.php | 126 ++++++++++++++++++----------------------- Zotlabs/Module/Queueworker.php | 6 +- 2 files changed, 57 insertions(+), 75 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/QueueWorker.php b/Zotlabs/Lib/QueueWorker.php index 2bcbdfc5c..da52fb859 100644 --- a/Zotlabs/Lib/QueueWorker.php +++ b/Zotlabs/Lib/QueueWorker.php @@ -2,11 +2,9 @@ namespace Zotlabs\Lib; - use Ramsey\Uuid\Uuid; use Ramsey\Uuid\Exception\UnableToBuildUuidException; - class QueueWorker { public static $queueworker = null; @@ -14,54 +12,25 @@ class QueueWorker { public static $workermaxage = 0; public static $workersleep = 100; public static $default_priorities = [ - 'Notifier' => 10, - 'Deliver' => 10, - 'Cache_query' => 10, - 'Content_importer' => 1, - 'File_importer' => 1, - 'Channel_purge' => 1, - 'Directory' => 1 + 'Notifier' => 10, + 'Deliver' => 10, + 'Cache_query' => 10, + 'Content_importer' => 1, + 'File_importer' => 1, + 'Channel_purge' => 1, + 'Directory' => 1 ]; private static function qbegin() { - switch (ACTIVE_DBTYPE) { - case DBTYPE_MYSQL: - q('BEGIN'); - break; - - case DBTYPE_POSTGRES: - q('BEGIN'); - break; - } - return; + q('BEGIN'); } private static function qcommit() { - switch (ACTIVE_DBTYPE) { - case DBTYPE_MYSQL: - //q("UNLOCK TABLES"); - q("COMMIT"); - break; - - case DBTYPE_POSTGRES: - q("COMMIT"); - break; - } - return; + q("COMMIT"); } private static function qrollback() { - switch (ACTIVE_DBTYPE) { - case DBTYPE_MYSQL: - q("ROLLBACK"); - //q("UNLOCK TABLES"); - break; - - case DBTYPE_POSTGRES: - q("ROLLBACK"); - break; - } - return; + q("ROLLBACK"); } public static function Summon($argv) { @@ -70,7 +39,7 @@ class QueueWorker { $priority = 0; // @TODO allow reprioritization - if(isset(self::$default_priorities[$argv[0]])) { + if (isset(self::$default_priorities[$argv[0]])) { $priority = self::$default_priorities[$argv[0]]; } @@ -83,8 +52,7 @@ class QueueWorker { ); if ($r) { logger("Summon: Ignoring duplicate workerq task", LOGGER_DEBUG); - logger(print_r($workinfo,true)); - $argv = []; + logger(print_r($workinfo, true)); return; } @@ -100,12 +68,12 @@ class QueueWorker { return; } self::qcommit(); - hz_syslog('INSERTED: ' . $workinfo_json, LOGGER_DEBUG); + logger('INSERTED: ' . $workinfo_json, LOGGER_DEBUG); } $workers = self::GetWorkerCount(); - if ($workers <= self::$maxworkers) { - hz_syslog("Less <= max active workers ($workers) max = " . self::$maxworkers . ".", LOGGER_DEBUG); + if ($workers < self::$maxworkers) { + logger($workers . '/' . self::$maxworkers . ' workers active', LOGGER_DEBUG); $phpbin = get_config('system', 'phpbin', 'php'); proc_run($phpbin, 'Zotlabs/Daemon/Master.php', ['Queueworker']); } @@ -116,7 +84,7 @@ class QueueWorker { if ($argv[0] !== 'Queueworker') { $priority = 0; // @TODO allow reprioritization - if(isset(self::$default_priorities[$argv[0]])) { + if (isset(self::$default_priorities[$argv[0]])) { $priority = self::$default_priorities[$argv[0]]; } @@ -129,9 +97,7 @@ class QueueWorker { ); if ($r) { logger("Release: Duplicate task - do not insert.", LOGGER_DEBUG); - logger(print_r($workinfo,true)); - - $argv = []; + logger(print_r($workinfo, true)); return; } @@ -177,14 +143,18 @@ class QueueWorker { if (self::$queueworker) { return self::$queueworker; } + $wid = uniqid('', true); - usleep(mt_rand(500000, 3000000)); //Sleep .5 - 3 seconds before creating a new worker. - $workers = self::GetWorkerCount(); - if ($workers >= self::$maxworkers) { + + usleep(mt_rand(300000, 1000000)); //Sleep .3 - 1 seconds before creating a new worker. + + if (self::GetWorkerCount() >= self::$maxworkers) { logger("Too many active workers ($workers) max = " . self::$maxworkers, LOGGER_DEBUG); return false; } + self::$queueworker = $wid; + return $wid; } @@ -193,17 +163,13 @@ class QueueWorker { self::qbegin(); - if (ACTIVE_DBTYPE == DBTYPE_POSTGRES) { - $work = dbq("SELECT workerq_id FROM workerq WHERE workerq_reservationid IS NULL ORDER BY workerq_priority DESC, workerq_id ASC LIMIT 1 FOR UPDATE SKIP LOCKED;"); - } - else { - $work = dbq("SELECT workerq_id FROM workerq WHERE workerq_reservationid IS NULL ORDER BY workerq_priority DESC, workerq_id ASC LIMIT 1 FOR UPDATE SKIP LOCKED;"); - } + $work = dbq("SELECT workerq_id FROM workerq WHERE workerq_reservationid IS NULL ORDER BY workerq_priority DESC, workerq_id ASC LIMIT 1 FOR UPDATE SKIP LOCKED;"); if (!$work) { self::qrollback(); return false; } + $id = $work[0]['workerq_id']; $work = q("UPDATE workerq SET workerq_reservationid = '%s', workerq_processtimeout = %s + INTERVAL %s WHERE workerq_id = %d", @@ -224,25 +190,38 @@ class QueueWorker { } public static function Process() { + $sleep = intval(get_config('queueworker', 'queue_worker_sleep', 100)); + $auto_queue_worker_sleep = get_config('queueworker', 'auto_queue_worker_sleep', 0); + if (!self::GetWorkerID()) { - hz_syslog('Unable to get worker ID. Exiting.', LOGGER_DEBUG); + if ($auto_queue_worker_sleep) { + set_config('queueworker', 'queue_worker_sleep', $sleep + 100); + } + + logger('Unable to get worker ID. Exiting.', LOGGER_DEBUG); killme(); } - $jobs = 0; - $workid = self::getWorkId(); + if ($auto_queue_worker_sleep && $sleep > 100) { + $next_sleep = $sleep - 100; + set_config('queueworker', 'queue_worker_sleep', (($next_sleep < 100) ? 100 : $next_sleep)); + } + + $jobs = 0; + $workid = self::getWorkId(); $load_average_sleep = false; - self::$workersleep = get_config('queueworker', 'queue_worker_sleep'); - self::$workersleep = ((intval(self::$workersleep) > 100) ? intval(self::$workersleep) : 100); + self::$workersleep = $sleep; + self::$workersleep = ((intval(self::$workersleep) > 100) ? intval(self::$workersleep) : 100); if (function_exists('sys_getloadavg') && get_config('queueworker', 'load_average_sleep')) { + // experimental! $load_average_sleep = true; } while ($workid) { if ($load_average_sleep) { - $load_average = sys_getloadavg(); + $load_average = sys_getloadavg(); self::$workersleep = intval($load_average[0]) * 10000; if (!self::$workersleep) { @@ -250,6 +229,8 @@ class QueueWorker { } } + logger('queue_worker_sleep: ' . self::$workersleep, LOGGER_DEBUG); + usleep(self::$workersleep); self::qbegin(); @@ -259,8 +240,8 @@ class QueueWorker { if (isset($workitem[0])) { // At least SOME work to do.... in case there's more, let's ramp up workers. $workers = self::GetWorkerCount(); - if ($workers <= self::$maxworkers) { - logger("Less <= max active workers ($workers) max = " . self::$maxworkers . ".", LOGGER_DEBUG); + if ($workers < self::$maxworkers) { + logger($workers . '/' . self::$maxworkers . ' workers active', LOGGER_DEBUG); $phpbin = get_config('system', 'phpbin', 'php'); proc_run($phpbin, 'Zotlabs/Daemon/Master.php', ['Queueworker']); } @@ -277,9 +258,11 @@ class QueueWorker { $rnd = random_string(); - hz_syslog('PROCESSING: ' . $rnd . ' ' . print_r($argv,true)); + logger('PROCESSING: ' . $rnd . ' ' . print_r($argv, true)); + $cls::run($argc, $argv); - hz_syslog('COMPLETED: ' . $rnd); + + logger('COMPLETED: ' . $rnd); // @FIXME: Right now we assume that if we get a return, everything is OK. // At some point we may want to test whether the run returns true/false @@ -326,7 +309,6 @@ class QueueWorker { //Make sure nothing new came in $work = q("select * from workerq"); } - return; } /** @@ -335,7 +317,7 @@ class QueueWorker { * @param string $data * @return string $uuid */ - private static function getUuid($data) { + private static function getUuid(string $data) { $namespace = '3a112e42-f147-4ccf-a78b-f6841339ea2a'; try { $uuid = Uuid::uuid5($namespace, $data)->toString(); diff --git a/Zotlabs/Module/Queueworker.php b/Zotlabs/Module/Queueworker.php index 808a9ed61..7c5e4f1cf 100644 --- a/Zotlabs/Module/Queueworker.php +++ b/Zotlabs/Module/Queueworker.php @@ -66,7 +66,7 @@ class Queueworker extends Controller { $maxqueueworkers = get_config('queueworker', 'max_queueworkers', 4); $maxqueueworkers = ($maxqueueworkers > 3) ? $maxqueueworkers : 4; - set_config('queueworker', 'max_queueworkers', $maxqueueworkers); + //set_config('queueworker', 'max_queueworkers', $maxqueueworkers); $sc = ''; @@ -81,7 +81,7 @@ class Queueworker extends Controller { $workermaxage = get_config('queueworker', 'queueworker_max_age'); $workermaxage = ($workermaxage >= 120) ? $workermaxage : 300; - set_config('queueworker', 'max_queueworker_age', $workermaxage); + //set_config('queueworker', 'max_queueworker_age', $workermaxage); $sc .= replace_macros(get_markup_template('field_input.tpl'), [ '$field' => [ @@ -94,7 +94,7 @@ class Queueworker extends Controller { $queueworkersleep = get_config('queueworker', 'queue_worker_sleep'); $queueworkersleep = ($queueworkersleep > 100) ? $queueworkersleep : 100; - set_config('queueworker', 'queue_worker_sleep', $queueworkersleep); + //set_config('queueworker', 'queue_worker_sleep', $queueworkersleep); $sc .= replace_macros(get_markup_template('field_input.tpl'), [ '$field' => [ -- cgit v1.2.3 From 34125177e8973a0a419a1ea3b2c18ff62b782d97 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 19 Dec 2022 09:04:24 +0000 Subject: streamline ap followers only privacy warning with current handling. also fixes possible php error. --- Zotlabs/Lib/ThreadItem.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php index e86e2cac1..d1b386c42 100644 --- a/Zotlabs/Lib/ThreadItem.php +++ b/Zotlabs/Lib/ThreadItem.php @@ -137,13 +137,7 @@ class ThreadItem { $shareable = false; } - $privacy_warning = false; - if(intval($item['item_private']) && ($item['owner']['xchan_network'] === 'activitypub')) { - $recips = get_iconfig($item['parent'], 'activitypub', 'recips'); - - if(! is_array($recips['to']) || ! in_array($observer['xchan_url'], $recips['to'])) - $privacy_warning = true; - } + $privacy_warning = ($item['owner']['xchan_network'] === 'activitypub' && intval($item['item_private']) === 1); if ($lock) { if (($item['mid'] == $item['parent_mid']) && isset($item['term']) && count(get_terms_oftype($item['term'], TERM_FORUM))) { -- cgit v1.2.3 From 7dd23085344a93d4fb1b3a9e4a60ca0b4fb78a95 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 20 Dec 2022 20:16:06 +0000 Subject: pooll fixes --- Zotlabs/Module/Item.php | 11 +++++++---- Zotlabs/Module/Vote.php | 6 ++---- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Item.php b/Zotlabs/Module/Item.php index 8e6106e79..27fc62ee6 100644 --- a/Zotlabs/Module/Item.php +++ b/Zotlabs/Module/Item.php @@ -1518,8 +1518,9 @@ class Item extends Controller { if (preg_match_all('/\[answer\](.*?)\[\/answer\]/ism', $body, $matches, PREG_SET_ORDER)) { foreach ($matches as $match) { - $ptr[] = ['name' => $match[1], 'type' => 'Note', 'replies' => ['type' => 'Collection', 'totalItems' => 0]]; - $body = str_replace('[answer]' . $match[1] . '[/answer]', EMPTY_STR, $body); + $answer = escape_tags(trim($match[1])); + $ptr[] = ['name' => $answer, 'type' => 'Note', 'replies' => ['type' => 'Collection', 'totalItems' => 0]]; + $body = str_replace('[answer]' . $answer . '[/answer]', EMPTY_STR, $body); } } @@ -1573,8 +1574,10 @@ class Item extends Controller { $obj['content'] = bbcode($question); foreach ($answers as $answer) { - if (trim($answer)) - $ptr[] = ['name' => escape_tags($answer), 'type' => 'Note', 'replies' => ['type' => 'Collection', 'totalItems' => 0]]; + $answer = escape_tags(trim($answer)); + if ($answer) { + $ptr[] = ['name' => $answer, 'type' => 'Note', 'replies' => ['type' => 'Collection', 'totalItems' => 0]]; + } } if ($multiple) { diff --git a/Zotlabs/Module/Vote.php b/Zotlabs/Module/Vote.php index 4f909d33d..870fd760c 100644 --- a/Zotlabs/Module/Vote.php +++ b/Zotlabs/Module/Vote.php @@ -45,9 +45,7 @@ class Vote extends Controller { if ($obj['oneOf']) { foreach($obj['oneOf'] as $selection) { - // logger('selection: ' . $selection); - // logger('response: ' . $response); - if($selection['name'] && $selection['name'] === $response) { + if($selection['name'] && htmlspecialchars_decode($selection['name']) === $response) { $valid = true; } } @@ -56,7 +54,7 @@ class Vote extends Controller { $choices = []; if ($obj['anyOf']) { foreach ($obj['anyOf'] as $selection) { - $choices[] = $selection['name']; + $choices[] = htmlspecialchars_decode($selection['name']); } foreach ($response as $res) { if (! in_array($res,$choices)) { -- cgit v1.2.3 From e5c70a1304c27aab915e1fc1415c5cfc5d14ed68 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 21 Dec 2022 17:11:33 +0000 Subject: queueworker: adjust process query to be complient with mariadb < 10.6 and add process timeout exceptions for long running processes --- Zotlabs/Lib/QueueWorker.php | 54 +++++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 16 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/QueueWorker.php b/Zotlabs/Lib/QueueWorker.php index da52fb859..eecf79907 100644 --- a/Zotlabs/Lib/QueueWorker.php +++ b/Zotlabs/Lib/QueueWorker.php @@ -21,8 +21,14 @@ class QueueWorker { 'Directory' => 1 ]; - private static function qbegin() { - q('BEGIN'); + // Exceptions for processtimeout value. + // Currently the value is overriden with 3600 seconds (1h). + public static $long_running_cmd = [ + 'Queue' + ]; + + private static function qstart() { + q('START TRANSACTION'); } private static function qcommit() { @@ -56,11 +62,12 @@ class QueueWorker { return; } - self::qbegin(); - $r = q("INSERT INTO workerq (workerq_priority, workerq_data, workerq_uuid) VALUES (%d, '%s', '%s')", + self::qstart(); + $r = q("INSERT INTO workerq (workerq_priority, workerq_data, workerq_uuid, workerq_cmd) VALUES (%d, '%s', '%s', '%s')", intval($priority), $workinfo_json, - dbesc($uuid) + dbesc($uuid), + dbesc($argv[0]) ); if (!$r) { self::qrollback(); @@ -101,11 +108,12 @@ class QueueWorker { return; } - self::qbegin(); - $r = q("INSERT INTO workerq (workerq_priority, workerq_data, workerq_uuid) VALUES (%d, '%s', '%s')", + self::qstart(); + $r = q("INSERT INTO workerq (workerq_priority, workerq_data, workerq_uuid, workerq_cmd) VALUES (%d, '%s', '%s', '%s')", intval($priority), $workinfo_json, - dbesc($uuid) + dbesc($uuid), + dbesc($argv[0]) ); if (!$r) { self::qrollback(); @@ -133,7 +141,8 @@ class QueueWorker { db_utcnow() ); - usleep(self::$workersleep); + //usleep(self::$workersleep); + $workers = dbq("select count(distinct workerq_reservationid) as total from workerq where workerq_reservationid is not null"); logger("WORKERCOUNT: " . $workers[0]['total'], LOGGER_DEBUG); return intval($workers[0]['total']); @@ -148,7 +157,9 @@ class QueueWorker { usleep(mt_rand(300000, 1000000)); //Sleep .3 - 1 seconds before creating a new worker. - if (self::GetWorkerCount() >= self::$maxworkers) { + $workers = self::GetWorkerCount(); + + if ($workers >= self::$maxworkers) { logger("Too many active workers ($workers) max = " . self::$maxworkers, LOGGER_DEBUG); return false; } @@ -161,21 +172,30 @@ class QueueWorker { private static function getWorkId() { self::GetWorkerCount(); - self::qbegin(); + self::qstart(); - $work = dbq("SELECT workerq_id FROM workerq WHERE workerq_reservationid IS NULL ORDER BY workerq_priority DESC, workerq_id ASC LIMIT 1 FOR UPDATE SKIP LOCKED;"); + // This is probably the better solution but is not supported by mariadb < 10.6 + // $work = dbq("SELECT workerq_id FROM workerq WHERE workerq_reservationid IS NULL ORDER BY workerq_priority DESC, workerq_id ASC LIMIT 1 FOR UPDATE SKIP LOCKED;"); + + $work = dbq("SELECT workerq_id, workerq_cmd FROM workerq WHERE workerq_reservationid IS NULL ORDER BY workerq_priority DESC, workerq_id ASC LIMIT 1 FOR UPDATE;"); if (!$work) { - self::qrollback(); + self::qcommit(); return false; } $id = $work[0]['workerq_id']; + $cmd = $work[0]['workerq_cmd']; + $age = self::$workermaxage; + + if (in_array($cmd, self::$long_running_cmd)) { + $age = 3600; // 1h TODO: make this configurable + } $work = q("UPDATE workerq SET workerq_reservationid = '%s', workerq_processtimeout = %s + INTERVAL %s WHERE workerq_id = %d", self::$queueworker, db_utcnow(), - db_quoteinterval(self::$workermaxage . " SECOND"), + db_quoteinterval($age . " SECOND"), intval($id) ); @@ -184,8 +204,10 @@ class QueueWorker { logger("Could not update workerq.", LOGGER_DEBUG); return false; } + logger("GOTWORK: " . json_encode($work), LOGGER_DEBUG); self::qcommit(); + return $id; } @@ -233,7 +255,7 @@ class QueueWorker { usleep(self::$workersleep); - self::qbegin(); + self::qstart(); $workitem = dbq("SELECT * FROM workerq WHERE workerq_id = $workid"); self::qcommit(); @@ -269,7 +291,7 @@ class QueueWorker { // and requeue the work to be tried again if needed. But we probably want // to implement some sort of "retry interval" first. - self::qbegin(); + self::qstart(); dbq("delete from workerq where workerq_id = $workid"); self::qcommit(); } -- cgit v1.2.3 From 1ba44fc117656233be82828e708d50cb3dcfc2d9 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 21 Dec 2022 17:15:34 +0000 Subject: update --- Zotlabs/Update/_1255.php | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Zotlabs/Update/_1255.php (limited to 'Zotlabs') diff --git a/Zotlabs/Update/_1255.php b/Zotlabs/Update/_1255.php new file mode 100644 index 000000000..4f1da1a4a --- /dev/null +++ b/Zotlabs/Update/_1255.php @@ -0,0 +1,29 @@ + Date: Thu, 22 Dec 2022 10:02:31 +0000 Subject: there is no point in wrapping single queries into a transaction --- Zotlabs/Lib/QueueWorker.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/QueueWorker.php b/Zotlabs/Lib/QueueWorker.php index eecf79907..8f816a619 100644 --- a/Zotlabs/Lib/QueueWorker.php +++ b/Zotlabs/Lib/QueueWorker.php @@ -21,7 +21,7 @@ class QueueWorker { 'Directory' => 1 ]; - // Exceptions for processtimeout value. + // Exceptions for processtimeout ($workermaxage) value. // Currently the value is overriden with 3600 seconds (1h). public static $long_running_cmd = [ 'Queue' @@ -145,6 +145,7 @@ class QueueWorker { $workers = dbq("select count(distinct workerq_reservationid) as total from workerq where workerq_reservationid is not null"); logger("WORKERCOUNT: " . $workers[0]['total'], LOGGER_DEBUG); + return intval($workers[0]['total']); } @@ -174,7 +175,7 @@ class QueueWorker { self::qstart(); - // This is probably the better solution but is not supported by mariadb < 10.6 + // This is probably the better solution but is not supported by mariadb < 10.6 which is still used a lot. // $work = dbq("SELECT workerq_id FROM workerq WHERE workerq_reservationid IS NULL ORDER BY workerq_priority DESC, workerq_id ASC LIMIT 1 FOR UPDATE SKIP LOCKED;"); $work = dbq("SELECT workerq_id, workerq_cmd FROM workerq WHERE workerq_reservationid IS NULL ORDER BY workerq_priority DESC, workerq_id ASC LIMIT 1 FOR UPDATE;"); @@ -255,9 +256,7 @@ class QueueWorker { usleep(self::$workersleep); - self::qstart(); $workitem = dbq("SELECT * FROM workerq WHERE workerq_id = $workid"); - self::qcommit(); if (isset($workitem[0])) { // At least SOME work to do.... in case there's more, let's ramp up workers. @@ -291,9 +290,7 @@ class QueueWorker { // and requeue the work to be tried again if needed. But we probably want // to implement some sort of "retry interval" first. - self::qstart(); dbq("delete from workerq where workerq_id = $workid"); - self::qcommit(); } else { logger("NO WORKITEM!", LOGGER_DEBUG); -- cgit v1.2.3 From 999e142370a8daaf6a668ba9bba0313c59ed4f1c Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 22 Dec 2022 10:09:35 +0000 Subject: minor cleanup --- Zotlabs/Lib/QueueWorker.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/QueueWorker.php b/Zotlabs/Lib/QueueWorker.php index 8f816a619..3a0e70f63 100644 --- a/Zotlabs/Lib/QueueWorker.php +++ b/Zotlabs/Lib/QueueWorker.php @@ -258,9 +258,10 @@ class QueueWorker { $workitem = dbq("SELECT * FROM workerq WHERE workerq_id = $workid"); - if (isset($workitem[0])) { + if ($workitem) { // At least SOME work to do.... in case there's more, let's ramp up workers. $workers = self::GetWorkerCount(); + if ($workers < self::$maxworkers) { logger($workers . '/' . self::$maxworkers . ' workers active', LOGGER_DEBUG); $phpbin = get_config('system', 'phpbin', 'php'); @@ -268,6 +269,7 @@ class QueueWorker { } $jobs++; + logger("Workinfo: " . $workitem[0]['workerq_data'], LOGGER_DEBUG); $workinfo = json_decode($workitem[0]['workerq_data'], true); @@ -276,10 +278,9 @@ class QueueWorker { $cls = '\\Zotlabs\\Daemon\\' . $argv[0]; $argv = flatten_array_recursive($argv); $argc = count($argv); - $rnd = random_string(); - logger('PROCESSING: ' . $rnd . ' ' . print_r($argv, true)); + logger('PROCESSING: ' . $rnd . ' ' . print_r($argv[0], true)); $cls::run($argc, $argv); @@ -307,24 +308,30 @@ class QueueWorker { $workinfo = json_decode($workitem['v'], true); $argc = $workinfo['argc']; $argv = $workinfo['argv']; + logger('Master: process: ' . print_r($argv, true), LOGGER_ALL, LOG_DEBUG); + if (!isset($argv[0])) { q("delete from workerq where workerq_id = %d", $work[0]['workerq_id'] ); continue; } + $cls = '\\Zotlabs\\Daemon\\' . $argv[0]; $cls::run($argc, $argv); + q("delete from workerq where workerq_id = %d", $work[0]['workerq_id'] ); - usleep(300000); + //Give the server .3 seconds to catch its breath between tasks. //This will hopefully keep it from crashing to it's knees entirely //if the last task ended up initiating other parallel processes //(eg. polling remotes) + usleep(300000); } + //Make sure nothing new came in $work = q("select * from workerq"); } -- cgit v1.2.3 From 2b0404fefc69678db7afa5e1f25a5f1fabd50907 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 22 Dec 2022 13:29:34 +0000 Subject: queueworker: add some more details --- Zotlabs/Module/Queueworker.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Queueworker.php b/Zotlabs/Module/Queueworker.php index 7c5e4f1cf..0e0529bc0 100644 --- a/Zotlabs/Module/Queueworker.php +++ b/Zotlabs/Module/Queueworker.php @@ -51,22 +51,24 @@ class Queueworker extends Controller { $content = "

Queue Status

\n"; - $r = q('select count(*) as qentries from workerq'); + $r = q('select count(*) as total from workerq'); - if (!$r) { - $content = "

There was an error querying the database.

"; - return $content; - } - - $content .= "

There are " . $r[0]['qentries'] . " queue items to be processed.

"; + $content .= "

There are " . $r[0]['total'] . " queue items to be processed.

"; $r = dbq("select count(distinct workerq_reservationid) as qworkers from workerq where workerq_reservationid is not null"); $content .= "

Active workers: " . $r[0]['qworkers'] . "

"; + $r = dbq("select workerq_cmd, count(*) as total from workerq where true group by workerq_cmd"); + + $content .= "

Work items

"; + + foreach($r as $rr) { + $content .= $rr['workerq_cmd'] . ': ' . $rr['total'] . '
'; + } + $maxqueueworkers = get_config('queueworker', 'max_queueworkers', 4); $maxqueueworkers = ($maxqueueworkers > 3) ? $maxqueueworkers : 4; - //set_config('queueworker', 'max_queueworkers', $maxqueueworkers); $sc = ''; @@ -81,7 +83,6 @@ class Queueworker extends Controller { $workermaxage = get_config('queueworker', 'queueworker_max_age'); $workermaxage = ($workermaxage >= 120) ? $workermaxage : 300; - //set_config('queueworker', 'max_queueworker_age', $workermaxage); $sc .= replace_macros(get_markup_template('field_input.tpl'), [ '$field' => [ @@ -94,7 +95,6 @@ class Queueworker extends Controller { $queueworkersleep = get_config('queueworker', 'queue_worker_sleep'); $queueworkersleep = ($queueworkersleep > 100) ? $queueworkersleep : 100; - //set_config('queueworker', 'queue_worker_sleep', $queueworkersleep); $sc .= replace_macros(get_markup_template('field_input.tpl'), [ '$field' => [ -- cgit v1.2.3 From a46e2c1e6db63b03552bba9d6699b8509fd6daa0 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 22 Dec 2022 13:35:46 +0000 Subject: only display details if there are any --- Zotlabs/Module/Queueworker.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Queueworker.php b/Zotlabs/Module/Queueworker.php index 0e0529bc0..440132881 100644 --- a/Zotlabs/Module/Queueworker.php +++ b/Zotlabs/Module/Queueworker.php @@ -61,10 +61,11 @@ class Queueworker extends Controller { $r = dbq("select workerq_cmd, count(*) as total from workerq where true group by workerq_cmd"); - $content .= "

Work items

"; - - foreach($r as $rr) { - $content .= $rr['workerq_cmd'] . ': ' . $rr['total'] . '
'; + if ($r) { + $content .= "

Work items

"; + foreach($r as $rr) { + $content .= $rr['workerq_cmd'] . ': ' . $rr['total'] . '
'; + } } $maxqueueworkers = get_config('queueworker', 'max_queueworkers', 4); -- cgit v1.2.3 From d2d6be73b8428c11c2461961a920ed3e3e656f64 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 26 Dec 2022 09:08:54 +0000 Subject: fix subquery in hq widget and order by hubloc_id desc in handle_tag() to make sure we get the most recent entry when using privacy tags --- Zotlabs/Widget/Messages.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Widget/Messages.php b/Zotlabs/Widget/Messages.php index 9a3f0fa9c..a7e3b08fc 100644 --- a/Zotlabs/Widget/Messages.php +++ b/Zotlabs/Widget/Messages.php @@ -69,10 +69,12 @@ class Messages { $vnotify_sql = ''; if (!($vnotify & VNOTIFY_LIKE)) { - $vnotify_sql = " AND c.verb NOT IN ('" . dbesc(ACTIVITY_LIKE) . "', '" . dbesc(ACTIVITY_DISLIKE) . "') "; + $vnotify_sql_c = " AND c.verb NOT IN ('" . dbesc(ACTIVITY_LIKE) . "', '" . dbesc(ACTIVITY_DISLIKE) . "') "; + $vnotify_sql_i = " AND i.verb NOT IN ('" . dbesc(ACTIVITY_LIKE) . "', '" . dbesc(ACTIVITY_DISLIKE) . "') "; } elseif (!feature_enabled(local_channel(), 'dislike')) { - $vnotify_sql = " AND c.verb NOT IN ('" . dbesc(ACTIVITY_DISLIKE) . "') "; + $vnotify_sql_c = " AND c.verb NOT IN ('" . dbesc(ACTIVITY_DISLIKE) . "') "; + $vnotify_sql_i = " AND i.verb NOT IN ('" . dbesc(ACTIVITY_DISLIKE) . "') "; } switch($type) { @@ -90,7 +92,7 @@ class Messages { } $items = q("SELECT *, - (SELECT count(*) FROM item c WHERE c.uid = %d AND c.parent = i.parent AND c.item_unseen = 1 AND c.item_thread_top = 0 $item_normal_c $vnotify_sql) AS unseen_count + (SELECT count(*) FROM item c WHERE c.uid = %d AND c.parent = i.parent AND c.item_unseen = 1 AND c.item_thread_top = 0 $item_normal_c $vnotify_sql_c) AS unseen_count FROM item i WHERE i.uid = %d AND i.created <= '%s' $type_sql -- cgit v1.2.3 From 633cd11c5b129a9712dbc6e7867284fa7999cea5 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 27 Dec 2022 10:44:54 +0000 Subject: move mod queueworker to /admin --- Zotlabs/Module/Admin/Queueworker.php | 106 ++++++++++++++++++++++++++++++ Zotlabs/Module/Queueworker.php | 123 ----------------------------------- Zotlabs/Widget/Admin.php | 1 + 3 files changed, 107 insertions(+), 123 deletions(-) create mode 100644 Zotlabs/Module/Admin/Queueworker.php delete mode 100644 Zotlabs/Module/Queueworker.php (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Admin/Queueworker.php b/Zotlabs/Module/Admin/Queueworker.php new file mode 100644 index 000000000..b7972b2db --- /dev/null +++ b/Zotlabs/Module/Admin/Queueworker.php @@ -0,0 +1,106 @@ + 3) ? $maxqueueworkers : 4; + set_config('queueworker', 'max_queueworkers', $maxqueueworkers); + + $maxworkerage = intval($_POST['queueworker_max_age']); + $maxworkerage = ($maxworkerage >= 120) ? $maxworkerage : 300; + set_config('queueworker', 'queueworker_max_age', $maxworkerage); + + $queueworkersleep = intval($_POST['queue_worker_sleep']); + $queueworkersleep = ($queueworkersleep > 100) ? $queueworkersleep : 100; + set_config('queueworker', 'queue_worker_sleep', $queueworkersleep); + + goaway(z_root() . '/admin/queueworker'); + } + + function get() { + + $content = "

Queue Status

\n"; + + $r = q('select count(*) as total from workerq'); + + $content .= "

There are " . $r[0]['total'] . " queue items to be processed.

"; + + $r = dbq("select count(distinct workerq_reservationid) as qworkers from workerq where workerq_reservationid is not null"); + + $content .= "

Active workers: " . $r[0]['qworkers'] . "

"; + + $r = dbq("select workerq_cmd, count(*) as total from workerq where true group by workerq_cmd"); + + if ($r) { + $content .= "

Work items

"; + foreach($r as $rr) { + $content .= $rr['workerq_cmd'] . ': ' . $rr['total'] . '
'; + } + } + + $maxqueueworkers = get_config('queueworker', 'max_queueworkers', 4); + $maxqueueworkers = ($maxqueueworkers > 3) ? $maxqueueworkers : 4; + + $sc = ''; + + $sc .= replace_macros(get_markup_template('field_input.tpl'), [ + '$field' => [ + 'queueworker_maxworkers', + t('Max queueworker threads'), + $maxqueueworkers, + t('Minimum 4, default 4') + ] + ]); + + $workermaxage = get_config('queueworker', 'queueworker_max_age'); + $workermaxage = ($workermaxage >= 120) ? $workermaxage : 300; + + $sc .= replace_macros(get_markup_template('field_input.tpl'), [ + '$field' => [ + 'queueworker_max_age', + t('Assume workers dead after'), + $workermaxage, + t('Minimum 120, default 300 seconds') + ] + ]); + + $queueworkersleep = get_config('queueworker', 'queue_worker_sleep'); + $queueworkersleep = ($queueworkersleep > 100) ? $queueworkersleep : 100; + + $sc .= replace_macros(get_markup_template('field_input.tpl'), [ + '$field' => [ + 'queue_worker_sleep', + t('Pause before starting next task'), + $queueworkersleep, + t('Minimum 100, default 100 microseconds') + ] + ]); + + $tpl = get_markup_template('settings_addon.tpl'); + $content .= replace_macros($tpl, [ + '$action_url' => 'queueworker', + '$form_security_token' => get_form_security_token('queueworker'), + '$title' => t('Queueworker Settings'), + '$content' => $sc, + '$baseurl' => z_root(), + '$submit' => t('Save') + ] + ); + + return $content; + + } +} diff --git a/Zotlabs/Module/Queueworker.php b/Zotlabs/Module/Queueworker.php deleted file mode 100644 index 440132881..000000000 --- a/Zotlabs/Module/Queueworker.php +++ /dev/null @@ -1,123 +0,0 @@ - 3) ? $maxqueueworkers : 4; - set_config('queueworker', 'max_queueworkers', $maxqueueworkers); - - $maxworkerage = intval($_POST['queueworker_max_age']); - $maxworkerage = ($maxworkerage >= 120) ? $maxworkerage : 300; - set_config('queueworker', 'queueworker_max_age', $maxworkerage); - - $queueworkersleep = intval($_POST['queue_worker_sleep']); - $queueworkersleep = ($queueworkersleep > 100) ? $queueworkersleep : 100; - set_config('queueworker', 'queue_worker_sleep', $queueworkersleep); - - goaway(z_root() . '/queueworker'); - } - - function get() { - - $content = "

ERROR: Page not found

"; - App::$error = 404; - - if (!local_channel()) { - return $content; - } - - if (!(is_site_admin())) { - return $content; - } - - load_config("queueworker"); - - $content = "

Queue Status

\n"; - - $r = q('select count(*) as total from workerq'); - - $content .= "

There are " . $r[0]['total'] . " queue items to be processed.

"; - - $r = dbq("select count(distinct workerq_reservationid) as qworkers from workerq where workerq_reservationid is not null"); - - $content .= "

Active workers: " . $r[0]['qworkers'] . "

"; - - $r = dbq("select workerq_cmd, count(*) as total from workerq where true group by workerq_cmd"); - - if ($r) { - $content .= "

Work items

"; - foreach($r as $rr) { - $content .= $rr['workerq_cmd'] . ': ' . $rr['total'] . '
'; - } - } - - $maxqueueworkers = get_config('queueworker', 'max_queueworkers', 4); - $maxqueueworkers = ($maxqueueworkers > 3) ? $maxqueueworkers : 4; - - $sc = ''; - - $sc .= replace_macros(get_markup_template('field_input.tpl'), [ - '$field' => [ - 'queueworker_maxworkers', - t('Max queueworker threads'), - $maxqueueworkers, - t('Minimum 4, default 4') - ] - ]); - - $workermaxage = get_config('queueworker', 'queueworker_max_age'); - $workermaxage = ($workermaxage >= 120) ? $workermaxage : 300; - - $sc .= replace_macros(get_markup_template('field_input.tpl'), [ - '$field' => [ - 'queueworker_max_age', - t('Assume workers dead after'), - $workermaxage, - t('Minimum 120, default 300 seconds') - ] - ]); - - $queueworkersleep = get_config('queueworker', 'queue_worker_sleep'); - $queueworkersleep = ($queueworkersleep > 100) ? $queueworkersleep : 100; - - $sc .= replace_macros(get_markup_template('field_input.tpl'), [ - '$field' => [ - 'queue_worker_sleep', - t('Pause before starting next task'), - $queueworkersleep, - t('Minimum 100, default 100 microseconds') - ] - ]); - - $tpl = get_markup_template('settings_addon.tpl'); - $content .= replace_macros($tpl, [ - '$action_url' => 'queueworker', - '$form_security_token' => get_form_security_token('queueworker'), - '$title' => t('Queueworker Settings'), - '$content' => $sc, - '$baseurl' => z_root(), - '$submit' => t('Save') - ] - ); - - return $content; - - } -} diff --git a/Zotlabs/Widget/Admin.php b/Zotlabs/Widget/Admin.php index 0a7a6925f..aa88de36a 100644 --- a/Zotlabs/Widget/Admin.php +++ b/Zotlabs/Widget/Admin.php @@ -32,6 +32,7 @@ class Admin { 'addons' => array(z_root() . '/admin/addons/', t('Addons'), 'addons'), 'themes' => array(z_root() . '/admin/themes/', t('Themes'), 'themes'), 'queue' => array(z_root() . '/admin/queue', t('Inspect queue'), 'queue'), + 'queueworker' => array(z_root() . '/admin/queueworker', t('Queueworker'), 'queueworker'), 'profs' => array(z_root() . '/admin/profs', t('Profile Fields'), 'profs'), 'dbsync' => array(z_root() . '/admin/dbsync/', t('DB updates'), 'dbsync') ]; -- cgit v1.2.3 From a30cfd8fec638a0f1d428c456f593e773f18b1bf Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 27 Dec 2022 16:08:08 +0000 Subject: filter approvals --- Zotlabs/Module/Sse_bs.php | 20 ++++++++++++++++++++ Zotlabs/Widget/Messages.php | 5 ++++- 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Sse_bs.php b/Zotlabs/Module/Sse_bs.php index ca9630c02..052870cc9 100644 --- a/Zotlabs/Module/Sse_bs.php +++ b/Zotlabs/Module/Sse_bs.php @@ -173,6 +173,9 @@ class Sse_bs extends Controller { $item_normal = item_normal(); + // FEP-5624 filter approvals for comments + $approvals = " AND verb NOT IN ('" . dbesc(ACTIVITY_ATTEND) . "', 'Accept', '" . dbesc(ACTIVITY_ATTENDNO) . "', 'Reject') "; + if ($notifications) { $items = q("SELECT * FROM item WHERE uid = %d @@ -181,6 +184,7 @@ class Sse_bs extends Controller { AND obj_type NOT IN ('Document', 'Video', 'Audio', 'Image') AND author_xchan != '%s' $item_normal + $approvals $sql_extra $sql_extra2 ORDER BY created DESC LIMIT $limit OFFSET $offset", @@ -210,6 +214,7 @@ class Sse_bs extends Controller { AND obj_type NOT IN ('Document', 'Video', 'Audio', 'Image') AND author_xchan != '%s' $item_normal + $approvals $sql_extra LIMIT 100", intval(self::$uid), dbesc(self::$ob_hash) @@ -253,6 +258,9 @@ class Sse_bs extends Controller { $item_normal = item_normal(); + // FEP-5624 filter approvals for comments + $approvals = " AND verb NOT IN ('" . dbesc(ACTIVITY_ATTEND) . "', 'Accept', '" . dbesc(ACTIVITY_ATTENDNO) . "', 'Reject') "; + if ($notifications) { $items = q("SELECT * FROM item WHERE uid = %d @@ -261,6 +269,7 @@ class Sse_bs extends Controller { AND obj_type NOT IN ('Document', 'Video', 'Audio', 'Image') AND author_xchan != '%s' $item_normal + $approvals $sql_extra $sql_extra2 ORDER BY created DESC LIMIT $limit OFFSET $offset", @@ -288,6 +297,7 @@ class Sse_bs extends Controller { $r = q("SELECT id FROM item WHERE uid = %d and item_unseen = 1 AND item_private = 2 $item_normal + $approvals $sql_extra AND author_xchan != '%s' LIMIT 100", intval(self::$uid), @@ -333,6 +343,9 @@ class Sse_bs extends Controller { $item_normal = item_normal(); + // FEP-5624 filter approvals for comments + $approvals = " AND verb NOT IN ('" . dbesc(ACTIVITY_ATTEND) . "', 'Accept', '" . dbesc(ACTIVITY_ATTENDNO) . "', 'Reject') "; + if ($notifications) { $items = q("SELECT * FROM item WHERE uid = %d @@ -341,6 +354,7 @@ class Sse_bs extends Controller { AND obj_type NOT IN ('Document', 'Video', 'Audio', 'Image') AND author_xchan != '%s' $item_normal + $approvals $sql_extra $sql_extra2 ORDER BY created DESC LIMIT $limit OFFSET $offset", @@ -368,6 +382,7 @@ class Sse_bs extends Controller { $r = q("SELECT id FROM item WHERE uid = %d and item_unseen = 1 AND item_wall = 1 AND item_private IN (0, 1) $item_normal + $approvals $sql_extra AND author_xchan != '%s' LIMIT 100", intval(self::$uid), @@ -430,6 +445,9 @@ class Sse_bs extends Controller { $item_normal = item_normal(); + // FEP-5624 filter approvals for comments + $approvals = " AND verb NOT IN ('" . dbesc(ACTIVITY_ATTEND) . "', 'Accept', '" . dbesc(ACTIVITY_ATTENDNO) . "', 'Reject') "; + if ($notifications) { $items = q("SELECT * FROM item WHERE true $uids @@ -438,6 +456,7 @@ class Sse_bs extends Controller { AND author_xchan != '%s' AND created > '%s' $item_normal + $approvals $sql_extra $sql_extra2 ORDER BY created DESC LIMIT $limit OFFSET $offset", @@ -465,6 +484,7 @@ class Sse_bs extends Controller { WHERE true $uids AND created > '%s' $item_normal + $approvals $sql_extra AND author_xchan != '%s' LIMIT 100", dbescdate($_SESSION['static_loadtime']), diff --git a/Zotlabs/Widget/Messages.php b/Zotlabs/Widget/Messages.php index a7e3b08fc..8c413e16e 100644 --- a/Zotlabs/Widget/Messages.php +++ b/Zotlabs/Widget/Messages.php @@ -91,8 +91,11 @@ class Messages { $type_sql = ' AND i.item_private IN (0, 1) '; } + // FEP-5624 filter approvals for comments + $approvals_c = " AND c.verb NOT IN ('" . dbesc(ACTIVITY_ATTEND) . "', 'Accept', '" . dbesc(ACTIVITY_ATTENDNO) . "', 'Reject') "; + $items = q("SELECT *, - (SELECT count(*) FROM item c WHERE c.uid = %d AND c.parent = i.parent AND c.item_unseen = 1 AND c.item_thread_top = 0 $item_normal_c $vnotify_sql_c) AS unseen_count + (SELECT count(*) FROM item c WHERE c.uid = %d AND c.parent = i.parent AND c.item_unseen = 1 AND c.item_thread_top = 0 $item_normal_c $approvals_c $vnotify_sql_c) AS unseen_count FROM item i WHERE i.uid = %d AND i.created <= '%s' $type_sql -- cgit v1.2.3 From 07417080865852fc82c866c5ea975ca5df3101a0 Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Sun, 1 Jan 2023 21:21:13 +0100 Subject: change the logic of building the site only public stream. we will now fetch sys channel items but restrict them to authors of this site only. this fixes a comment permission issue. --- Zotlabs/Module/Pubstream.php | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Pubstream.php b/Zotlabs/Module/Pubstream.php index 47da3c13a..d9156e4bf 100644 --- a/Zotlabs/Module/Pubstream.php +++ b/Zotlabs/Module/Pubstream.php @@ -158,16 +158,13 @@ class Pubstream extends \Zotlabs\Web\Controller { require_once('include/security.php'); $sys = get_sys_channel(); + $uids = " and item.uid = " . intval($sys['channel_id']) . " "; $abook_uids = " and abook.abook_channel = " . intval($sys['channel_id']) . " "; - $sql_extra = ''; + $sql_extra = item_permissions_sql($sys['channel_id']); + $site_firehose_sql = ''; if($site_firehose) { - $uids = " and item.uid in ( " . stream_perms_api_uids(PERMS_PUBLIC) . " ) and item_private = 0 and item_wall = 1 "; - } - else { - $uids = " and item.uid = " . intval($sys['channel_id']) . " "; - $sql_extra .= item_permissions_sql($sys['channel_id']); - \App::$data['firehose'] = intval($sys['channel_id']); + $site_firehose_sql = " and author_xchan in (select channel_hash from channel where channel_system = 0 and channel_removed = 0) "; } if(get_config('system','public_list_mode')) @@ -199,7 +196,9 @@ class Pubstream extends \Zotlabs\Web\Controller { $r = q("SELECT parent AS item_id FROM item left join abook on item.author_xchan = abook.abook_xchan $net_query - WHERE mid = '%s' $uids $item_normal + WHERE item.mid = '%s' and item.item_private = 0 + $uids $site_firehose_sql + $item_normal and (abook.abook_blocked = 0 or abook.abook_flags is null) $sql_extra $net_query2", dbesc($mid) @@ -207,10 +206,12 @@ class Pubstream extends \Zotlabs\Web\Controller { } else { // Fetch a page full of parent items for this page - $r = dbq("SELECT item.id AS item_id FROM item + $r = dbq("SELECT parent AS item_id FROM item left join abook on ( item.author_xchan = abook.abook_xchan $abook_uids ) $net_query - WHERE true $uids and item.item_thread_top = 1 $item_normal + WHERE item.item_private = 0 and item.item_thread_top = 1 + $uids $site_firehose_sql + $item_normal and (abook.abook_blocked = 0 or abook.abook_flags is null) $sql_extra $net_query2 ORDER BY $ordering DESC $pager_sql " @@ -222,7 +223,8 @@ class Pubstream extends \Zotlabs\Web\Controller { $r = q("SELECT parent AS item_id FROM item left join abook on item.author_xchan = abook.abook_xchan $net_query - WHERE mid = '%s' $uids $item_normal_update $simple_update + WHERE item.mid = '%s' and item.item_private = 0 + $uids $site_firehose_sql $item_normal_update $simple_update and (abook.abook_blocked = 0 or abook.abook_flags is null) $sql_extra $net_query2", dbesc($mid) @@ -232,7 +234,8 @@ class Pubstream extends \Zotlabs\Web\Controller { $r = dbq("SELECT parent AS item_id FROM item left join abook on item.author_xchan = abook.abook_xchan $net_query - WHERE true $uids $item_normal_update + WHERE item.item_private = 0 and item.item_thread_top = 1 + $uids $site_firehose_sql $item_normal_update $simple_update and (abook.abook_blocked = 0 or abook.abook_flags is null) $sql_extra $net_query2" @@ -256,7 +259,7 @@ class Pubstream extends \Zotlabs\Web\Controller { // use effective_uid param of xchan_query to help sort out comment permission // for sys_channel owned items. - xchan_query($items,true,(($sys) ? local_channel() : 0)); + xchan_query($items, true, local_channel()); $items = fetch_post_tags($items,true); $items = conv_sort($items,$ordering); } -- cgit v1.2.3 From b96dc11ddd039a0bfeab9f1b745afc044d9487f8 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 2 Jan 2023 18:37:36 +0000 Subject: improve sse loop --- Zotlabs/Module/Sse.php | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Sse.php b/Zotlabs/Module/Sse.php index f87a19821..8b46dcafd 100644 --- a/Zotlabs/Module/Sse.php +++ b/Zotlabs/Module/Sse.php @@ -50,7 +50,7 @@ class Sse extends Controller { self::$vnotify = get_pconfig(self::$uid, 'system', 'vnotify'); } - $sleep_seconds = 3; + $sleep = 1000000; // microseconds self::$sse_enabled = get_config('system', 'sse_enabled', 0); @@ -63,17 +63,24 @@ class Sse extends Controller { header("Connection: keep-alive"); header("X-Accel-Buffering: no"); - while(true) { + $i = 0; - if(! self::$sse_id) { + while(true) { - // Update chat presence indication + // reset counter for updating chatpresence about every minute + if (($i * $sleep)/60 > 1000000) { + $i = 0; + } + if(!self::$sse_id && $i === 0) { + // Update chat presence indication about once per minute $r = q("select cp_id, cp_room from chatpresence where cp_xchan = '%s' and cp_client = '%s' and cp_room = 0 limit 1", dbesc(self::$ob_hash), dbesc($_SERVER['REMOTE_ADDR']) ); + $basic_presence = false; + if($r) { $basic_presence = true; q("update chatpresence set cp_last = '%s' where cp_id = %d", @@ -81,7 +88,8 @@ class Sse extends Controller { intval($r[0]['cp_id']) ); } - if(! $basic_presence) { + + if(!$basic_presence) { q("insert into chatpresence ( cp_xchan, cp_last, cp_status, cp_client) values( '%s', '%s', '%s', '%s' ) ", dbesc(self::$ob_hash), @@ -94,9 +102,14 @@ class Sse extends Controller { XConfig::Load(self::$ob_hash); - $result = XConfig::Get(self::$ob_hash, 'sse', 'notifications', []); + $result = []; $lock = XConfig::Get(self::$ob_hash, 'sse', 'lock'); + if (!$lock) { + $result = XConfig::Get(self::$ob_hash, 'sse', 'notifications', []); + } + + // We do not have the local_channel in the addon. // Reset pubs here if the app is not installed. if (self::$uid && (!(self::$vnotify & VNOTIFY_PUBS) || !Apps::system_app_installed(self::$uid, 'Public Stream'))) { @@ -105,7 +118,7 @@ class Sse extends Controller { } } - if($result && !$lock) { + if($result) { echo "event: notifications\n"; echo 'data: ' . json_encode($result); echo "\n\n"; @@ -121,6 +134,7 @@ class Sse extends Controller { if(ob_get_length() > 0) ob_end_flush(); + flush(); if(connection_status() != CONNECTION_NORMAL || connection_aborted()) { @@ -129,7 +143,9 @@ class Sse extends Controller { break; } - sleep($sleep_seconds); + $i++; + + usleep($sleep); } -- cgit v1.2.3 From 0e71bfe2224b8fc54a58aff80894e1f22294bd6e Mon Sep 17 00:00:00 2001 From: Mario Vavti Date: Mon, 2 Jan 2023 20:38:56 +0100 Subject: add sys channel to receiveres for public items --- Zotlabs/Daemon/Notifier.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Notifier.php b/Zotlabs/Daemon/Notifier.php index bfccb4099..f51dfab28 100644 --- a/Zotlabs/Daemon/Notifier.php +++ b/Zotlabs/Daemon/Notifier.php @@ -509,6 +509,7 @@ class Notifier { // public posts won't make it to the local public stream unless there's a recipient on this site. // This code block sees if it's a public post and localhost is missing, and if so adds an entry for the local sys channel to the $hubs list + /* sys channel is now added in collect recipients if (!self::$private) { $found_localhost = false; if ($hubs) { @@ -529,6 +530,7 @@ class Notifier { } } } + */ if (!$hubs) { logger('notifier: no hubs', LOGGER_NORMAL, LOG_NOTICE); -- cgit v1.2.3 From de0d2afc154196ed80960435ac9c74ce37635576 Mon Sep 17 00:00:00 2001 From: Mario Date: Mon, 2 Jan 2023 21:56:20 +0000 Subject: fix issues with pubstream tagcloud --- Zotlabs/Module/Pubstream.php | 21 ++++++++++++++++----- Zotlabs/Widget/Pubtagcloud.php | 17 ++++++----------- 2 files changed, 22 insertions(+), 16 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Pubstream.php b/Zotlabs/Module/Pubstream.php index d9156e4bf..7b8d75727 100644 --- a/Zotlabs/Module/Pubstream.php +++ b/Zotlabs/Module/Pubstream.php @@ -161,10 +161,12 @@ class Pubstream extends \Zotlabs\Web\Controller { $uids = " and item.uid = " . intval($sys['channel_id']) . " "; $abook_uids = " and abook.abook_channel = " . intval($sys['channel_id']) . " "; $sql_extra = item_permissions_sql($sys['channel_id']); + $sql_extra_order = ''; $site_firehose_sql = ''; + $thread_top = " and item.item_thread_top = 1 "; if($site_firehose) { - $site_firehose_sql = " and author_xchan in (select channel_hash from channel where channel_system = 0 and channel_removed = 0) "; + $site_firehose_sql = " and owner_xchan in (select channel_hash from channel where channel_system = 0 and channel_removed = 0) "; } if(get_config('system','public_list_mode')) @@ -175,6 +177,8 @@ class Pubstream extends \Zotlabs\Web\Controller { if(x($hashtags)) { $sql_extra .= protect_sprintf(term_query('item', $hashtags, TERM_HASHTAG, TERM_COMMUNITYTAG)); + $sql_extra_order = " ORDER BY item.created DESC "; + $thread_top = ''; } $net_query = (($net) ? " left join xchan on xchan_hash = author_xchan " : ''); @@ -209,7 +213,7 @@ class Pubstream extends \Zotlabs\Web\Controller { $r = dbq("SELECT parent AS item_id FROM item left join abook on ( item.author_xchan = abook.abook_xchan $abook_uids ) $net_query - WHERE item.item_private = 0 and item.item_thread_top = 1 + WHERE item.item_private = 0 $thread_top $uids $site_firehose_sql $item_normal and (abook.abook_blocked = 0 or abook.abook_flags is null) @@ -234,7 +238,7 @@ class Pubstream extends \Zotlabs\Web\Controller { $r = dbq("SELECT parent AS item_id FROM item left join abook on item.author_xchan = abook.abook_xchan $net_query - WHERE item.item_private = 0 and item.item_thread_top = 1 + WHERE item.item_private = 0 $thread_top $uids $site_firehose_sql $item_normal_update $simple_update and (abook.abook_blocked = 0 or abook.abook_flags is null) @@ -253,15 +257,22 @@ class Pubstream extends \Zotlabs\Web\Controller { $items = dbq("SELECT item.*, item.id AS item_id FROM item WHERE true $uids $item_normal AND item.parent IN ( $parents_str ) - $sql_extra" + $sql_extra $sql_extra_order" ); + + // use effective_uid param of xchan_query to help sort out comment permission // for sys_channel owned items. xchan_query($items, true, local_channel()); $items = fetch_post_tags($items,true); - $items = conv_sort($items,$ordering); + + if (!$hashtags) { + $items = conv_sort($items, $ordering); + } + + } } diff --git a/Zotlabs/Widget/Pubtagcloud.php b/Zotlabs/Widget/Pubtagcloud.php index db7ea02e7..90bf5eb97 100644 --- a/Zotlabs/Widget/Pubtagcloud.php +++ b/Zotlabs/Widget/Pubtagcloud.php @@ -22,24 +22,19 @@ class Pubtagcloud { } } - $site_firehose = ((intval(get_config('system','site_firehose',0))) ? true : false); - $net_firehose = ((get_config('system','disable_discover_tab',1)) ? false : true); + $net_firehose = ((get_config('system','disable_discover_tab',1)) ? false : true); - if(! ($site_firehose || $net_firehose)) { - return EMPTY_STR; - } + if(!$net_firehose) { + return ''; + } - if($net_firehose) { - $site_firehose = false; - } + $site_firehose = ((intval(get_config('system','site_firehose',0))) ? true : false); $safemode = get_xconfig(get_observer_hash(),'directory','safemode',1); - - $limit = ((array_key_exists('limit', $arr)) ? intval($arr['limit']) : 75); - return pubtagblock($net_firehose,$site_firehose, $limit, $trending, $safemode); + return pubtagblock($net_firehose, $site_firehose, $limit, $trending, $safemode); return ''; } -- cgit v1.2.3 From da9349ea621fbb506b0e1d78a8bf0a8f3958b48e Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 3 Jan 2023 10:59:38 +0000 Subject: provide inline error messages for mod cloud --- Zotlabs/Module/Cloud.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Cloud.php b/Zotlabs/Module/Cloud.php index 4cc7595a1..d82e0bd47 100644 --- a/Zotlabs/Module/Cloud.php +++ b/Zotlabs/Module/Cloud.php @@ -100,7 +100,6 @@ class Cloud extends Controller { // over-ride the default XML output on thrown exceptions - $server->on('exception', [ $this, 'DAVException' ]); // All we need to do now, is to fire up the server @@ -117,21 +116,19 @@ class Cloud extends Controller { function DAVException($err) { if($err instanceof \Sabre\DAV\Exception\NotFound) { - notice( t('Not found') . EOL); + \App::$page['content'] = '

404 Not found

'; } elseif($err instanceof \Sabre\DAV\Exception\Forbidden) { - notice( t('Permission denied') . EOL); + \App::$page['content'] = '

403 Forbidden

'; } elseif($err instanceof \Sabre\DAV\Exception\NotImplemented) { - // notice( t('Please refresh page') . EOL); - goaway(z_root() . '/' . \App::$query_string); + \App::$page['content'] = '

501 Not implemented

'; } else { - notice( t('Unknown error') . EOL); + \App::$page['content'] = '

500 Unknown error

'; } construct_page(); - killme(); } -- cgit v1.2.3 From d2edef5c5a9821337d9985eb00aab4281e480ecf Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 3 Jan 2023 13:30:53 +0000 Subject: go away if method is not implemented --- Zotlabs/Module/Cloud.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Cloud.php b/Zotlabs/Module/Cloud.php index d82e0bd47..05109247a 100644 --- a/Zotlabs/Module/Cloud.php +++ b/Zotlabs/Module/Cloud.php @@ -122,10 +122,10 @@ class Cloud extends Controller { \App::$page['content'] = '

403 Forbidden

'; } elseif($err instanceof \Sabre\DAV\Exception\NotImplemented) { - \App::$page['content'] = '

501 Not implemented

'; + goaway(z_root() . '/' . \App::$query_string); } else { - \App::$page['content'] = '

500 Unknown error

'; + \App::$page['content'] = '

Unknown error

'; } construct_page(); -- cgit v1.2.3 From 29776ecea2a38eb45f9e0628b1b674c1d7d0df93 Mon Sep 17 00:00:00 2001 From: Mario Date: Tue, 3 Jan 2023 13:50:22 +0000 Subject: queueworker: implement auto_queue_worker_sleep setting in frontend --- Zotlabs/Lib/QueueWorker.php | 2 +- Zotlabs/Module/Admin/Queueworker.php | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/QueueWorker.php b/Zotlabs/Lib/QueueWorker.php index 3a0e70f63..fd2ebd7e1 100644 --- a/Zotlabs/Lib/QueueWorker.php +++ b/Zotlabs/Lib/QueueWorker.php @@ -237,7 +237,7 @@ class QueueWorker { self::$workersleep = ((intval(self::$workersleep) > 100) ? intval(self::$workersleep) : 100); if (function_exists('sys_getloadavg') && get_config('queueworker', 'load_average_sleep')) { - // experimental! + // very experimental! $load_average_sleep = true; } diff --git a/Zotlabs/Module/Admin/Queueworker.php b/Zotlabs/Module/Admin/Queueworker.php index b7972b2db..45a09bf04 100644 --- a/Zotlabs/Module/Admin/Queueworker.php +++ b/Zotlabs/Module/Admin/Queueworker.php @@ -27,6 +27,9 @@ class Queueworker extends Controller { $queueworkersleep = ($queueworkersleep > 100) ? $queueworkersleep : 100; set_config('queueworker', 'queue_worker_sleep', $queueworkersleep); + $auto_queue_worker_sleep = intval($_POST['auto_queue_worker_sleep']); + set_config('queueworker', 'auto_queue_worker_sleep', $auto_queue_worker_sleep); + goaway(z_root() . '/admin/queueworker'); } @@ -80,18 +83,30 @@ class Queueworker extends Controller { $queueworkersleep = get_config('queueworker', 'queue_worker_sleep'); $queueworkersleep = ($queueworkersleep > 100) ? $queueworkersleep : 100; + $auto_queue_worker_sleep = get_config('queueworker', 'auto_queue_worker_sleep', 0); + $sc .= replace_macros(get_markup_template('field_input.tpl'), [ '$field' => [ 'queue_worker_sleep', t('Pause before starting next task'), $queueworkersleep, - t('Minimum 100, default 100 microseconds') + t('Minimum 100, default 100 microseconds'), + '', + (($auto_queue_worker_sleep) ? 'disabled' : '') + ] + ]); + + $sc .= replace_macros(get_markup_template('field_checkbox.tpl'), [ + '$field' => [ + 'auto_queue_worker_sleep', + t('Automatically adjust pause before starting next task'), + $auto_queue_worker_sleep, ] ]); $tpl = get_markup_template('settings_addon.tpl'); $content .= replace_macros($tpl, [ - '$action_url' => 'queueworker', + '$action_url' => 'admin/queueworker', '$form_security_token' => get_form_security_token('queueworker'), '$title' => t('Queueworker Settings'), '$content' => $sc, -- cgit v1.2.3 From e16ea1ae0568238fa4c2236d1f050ef4a85749c7 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 4 Jan 2023 14:25:46 +0000 Subject: pdl editor for addon iitial commit --- Zotlabs/Module/Pdledit.php | 37 ++++++++++++++++++++++++++++++++++--- Zotlabs/Module/Pdledit_gui.php | 42 +++++++++++++++++++++++++++++++++++++++--- Zotlabs/Widget/Categories.php | 2 +- 3 files changed, 74 insertions(+), 7 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Pdledit.php b/Zotlabs/Module/Pdledit.php index 3b94c9611..e0bbc31d0 100644 --- a/Zotlabs/Module/Pdledit.php +++ b/Zotlabs/Module/Pdledit.php @@ -78,6 +78,23 @@ class Pdledit extends Controller { } } + // addons + $o .= '

Addons

'; + + $addons = plugins_installed_list(); + + foreach ($addons as $addon) { + + $path = 'addon/' . $addon . '/Mod_' . ucfirst($addon) . '.php'; + + if (!file_exists($path)) + continue; + + $o .= '' . $addon . '' . ((in_array($addon, $edited)) ? ' ' . t('(modified)') . ' ' . t('Reset') . '': '' ) . '
'; + + } + + $o .= ''; // list module pdl files @@ -85,11 +102,25 @@ class Pdledit extends Controller { } $t = get_pconfig(local_channel(),'system',$module); - $s = file_get_contents(theme_include($module)); - if(! $t) { + $s = ''; + + if(!$t) { + $sys_path = theme_include($module); + + if ($sys_path) { + $s = file_get_contents($sys_path); + } + else { + $addon_path = 'addon/' . argv(1) . '/' . $module; + if (file_exists($addon_path)) { + $s = file_get_contents($addon_path); + } + } + $t = $s; } - if(! $t) { + + if(!$t) { notice( t('Layout not found.') . EOL); return ''; } diff --git a/Zotlabs/Module/Pdledit_gui.php b/Zotlabs/Module/Pdledit_gui.php index b550b92d3..d8d362831 100644 --- a/Zotlabs/Module/Pdledit_gui.php +++ b/Zotlabs/Module/Pdledit_gui.php @@ -237,18 +237,45 @@ class Pdledit_gui extends Controller { } } + $addons = plugins_installed_list(); + if ($addons) { + foreach ($addons as $name) { + $path = 'addon/' . $name . '/Mod_' . ucfirst($name) . '.php'; + + if (!file_exists($path)) { + continue; + } + + $ret .= ''; + } + } + return $ret; } function get_widgets($module) { $ret = []; + $checkpaths = [ 'Zotlabs/Widget/*.php' ]; + $addons = plugins_installed_list(); + + if ($addons) { + foreach ($addons as $name) { + $path = 'addon/' . $name . '/Widget'; + + if (is_dir($path)) { + $checkpaths[] = $path . '/*.php'; + } + } + } + foreach ($checkpaths as $path) { $files = glob($path); + if($files) { foreach($files as $f) { $name = lcfirst(basename($f, '.php')); @@ -536,12 +563,21 @@ class Pdledit_gui extends Controller { 'modified' => true ]; - $pdl_path = 'mod_' . $module . '.pdl'; + $pdl = 'mod_' . $module . '.pdl'; + $pdl_path = ''; - $ret['pdl'] = get_pconfig(local_channel(), 'system', $pdl_path); + $ret['pdl'] = get_pconfig(local_channel(), 'system', $pdl); if(!$ret['pdl']) { - $pdl_path = theme_include($pdl_path); + $pdl_path = theme_include($pdl); + + if (!$pdl_path) { + $addon_path = 'addon/' . $module . '/' . $pdl; + if (file_exists($addon_path)) { + $pdl_path = $addon_path; + } + } + if ($pdl_path) { $ret['pdl'] = file_get_contents($pdl_path); $ret['modified'] = false; diff --git a/Zotlabs/Widget/Categories.php b/Zotlabs/Widget/Categories.php index b0eda253b..7e6a3c6f7 100644 --- a/Zotlabs/Widget/Categories.php +++ b/Zotlabs/Widget/Categories.php @@ -3,7 +3,7 @@ /** * * Name: Categories * * Description: Display a menu with links to categories - * * Requires: channel, articles, cards, cloud + * * Requires: channel, cloud */ namespace Zotlabs\Widget; -- cgit v1.2.3 From 3ad36db7dd3fe848937776d56a7c9243543ce887 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 4 Jan 2023 19:27:44 +0000 Subject: pdledit_gui: minor cleanup --- Zotlabs/Module/Pdledit_gui.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Pdledit_gui.php b/Zotlabs/Module/Pdledit_gui.php index d8d362831..2f0e4a3e1 100644 --- a/Zotlabs/Module/Pdledit_gui.php +++ b/Zotlabs/Module/Pdledit_gui.php @@ -220,6 +220,7 @@ class Pdledit_gui extends Controller { function get_modules() { $ret = ''; + $arr = []; $files = glob('Zotlabs/Module/*.php'); if($files) { @@ -232,7 +233,7 @@ class Pdledit_gui extends Controller { $x = theme_include('mod_' . $name . '.pdl'); if($x) { - $ret .= ''; + $arr[] = $name; } } } @@ -240,17 +241,21 @@ class Pdledit_gui extends Controller { $addons = plugins_installed_list(); if ($addons) { foreach ($addons as $name) { - $path = 'addon/' . $name . '/Mod_' . ucfirst($name) . '.php'; - - if (!file_exists($path)) { - continue; + $path = 'addon/' . $name . '/mod_' . $name . '.pdl'; + if (file_exists($path)) { + $arr[] = $name; } - - $ret .= ''; } } + sort($arr); + + foreach ($arr as $name) { + $ret .= ''; + } + return $ret; + } function get_widgets($module) { -- cgit v1.2.3 From 031df70cf83b19987f4d9c417f6f5fbbdf0fd983 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 4 Jan 2023 19:29:11 +0000 Subject: pdledit_gui: minor cleanup --- Zotlabs/Module/Pdledit_gui.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Pdledit_gui.php b/Zotlabs/Module/Pdledit_gui.php index 2f0e4a3e1..d6766b09d 100644 --- a/Zotlabs/Module/Pdledit_gui.php +++ b/Zotlabs/Module/Pdledit_gui.php @@ -304,6 +304,8 @@ class Pdledit_gui extends Controller { } } +hz_syslog(print_r($ret,true)); + return $ret; } -- cgit v1.2.3 From 1a283301cf781c892a017094bf75e6b8e72fc4cd Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 4 Jan 2023 19:29:42 +0000 Subject: Revert "pdledit_gui: minor cleanup" This reverts commit 031df70cf83b19987f4d9c417f6f5fbbdf0fd983. --- Zotlabs/Module/Pdledit_gui.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Pdledit_gui.php b/Zotlabs/Module/Pdledit_gui.php index d6766b09d..2f0e4a3e1 100644 --- a/Zotlabs/Module/Pdledit_gui.php +++ b/Zotlabs/Module/Pdledit_gui.php @@ -304,8 +304,6 @@ class Pdledit_gui extends Controller { } } -hz_syslog(print_r($ret,true)); - return $ret; } -- cgit v1.2.3 From e69fabcd712d409a67de3c1245a229a8e1b6f98d Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 4 Jan 2023 19:33:18 +0000 Subject: pdledi_gui: sort widgets --- Zotlabs/Module/Pdledit_gui.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Pdledit_gui.php b/Zotlabs/Module/Pdledit_gui.php index 2f0e4a3e1..dadb3296e 100644 --- a/Zotlabs/Module/Pdledit_gui.php +++ b/Zotlabs/Module/Pdledit_gui.php @@ -304,6 +304,8 @@ class Pdledit_gui extends Controller { } } + usort($ret, fn($a, $b) => $a['name'] <=> $b['name']); + return $ret; } -- cgit v1.2.3 From 2eb4d8762101df4e5dc6feddcfd479727853763b Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 4 Jan 2023 20:14:11 +0000 Subject: fix issue #1717 --- Zotlabs/Module/Settings/Account.php | 57 +++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Settings/Account.php b/Zotlabs/Module/Settings/Account.php index 97cc9389a..5e1fb176e 100644 --- a/Zotlabs/Module/Settings/Account.php +++ b/Zotlabs/Module/Settings/Account.php @@ -6,11 +6,11 @@ class Account { function post() { check_form_security_token_redirectOnErr('/settings/account', 'settings_account'); - + call_hooks('account_settings_post', $_POST); - + $errs = array(); - + $email = ((x($_POST,'email')) ? trim(notags($_POST['email'])) : ''); $account = \App::get_account(); @@ -34,38 +34,38 @@ class Account { } } } - + if($errs) { foreach($errs as $err) notice($err . EOL); $errs = array(); } - - + + if((x($_POST,'npassword')) || (x($_POST,'confirm'))) { - + $origpass = trim($_POST['origpass']); - + require_once('include/auth.php'); if(! account_verify_password($email,$origpass)) { $errs[] = t('Password verification failed.'); } - + $newpass = trim($_POST['npassword']); $confirm = trim($_POST['confirm']); - + if($newpass != $confirm ) { $errs[] = t('Passwords do not match. Password unchanged.'); } - + if((! x($newpass)) || (! x($confirm))) { $errs[] = t('Empty passwords are not allowed. Password unchanged.'); } - + if(! $errs) { $salt = random_string(32); $password_encoded = hash('whirlpool', $salt . $newpass); - $r = q("update account set account_salt = '%s', account_password = '%s', account_password_changed = '%s' + $r = q("update account set account_salt = '%s', account_password = '%s', account_password_changed = '%s' where account_id = %d", dbesc($salt), dbesc($password_encoded), @@ -78,36 +78,37 @@ class Account { $errs[] = t('Password update failed. Please try again.'); } } - - + + if($errs) { foreach($errs as $err) notice($err . EOL); } goaway(z_root() . '/settings/account' ); } - - + + function get() { $account_settings = ""; - + call_hooks('account_settings', $account_settings); - + $email = \App::$account['account_email']; - $attremail = (!strpos($email, '@')) ? 'disabled="disabled"' : ''; + $attremail = ((!strpos($email, '@')) ? 'disabled="disabled"' : ''); $tpl = get_markup_template("settings_account.tpl"); $o .= replace_macros($tpl, array( '$form_security_token' => get_form_security_token("settings_account"), - '$title' => t('Account Settings'), - '$origpass' => array('origpass', t('Current Password'), ' ',''), - '$password1'=> array('npassword', t('Enter New Password'), '', ''), - '$password2'=> array('confirm', t('Confirm New Password'), '', t('Leave password fields blank unless changing')), - '$submit' => t('Submit'), - '$email' => array('email', t('DId2 or Email Address:'), $email, '', '', $attremail), - '$removeme' => t('Remove Account'), - '$removeaccount' => t('Remove this account including all its channels'), + '$title' => t('Account Settings'), + '$origpass' => array('origpass', t('Current Password'), ' ',''), + '$password1' => array('npassword', t('Enter New Password'), '', ''), + '$password2' => array('confirm', t('Confirm New Password'), '', t('Leave password fields blank unless changing')), + '$submit' => t('Submit'), + '$email' => array('email', t('DId2 or Email Address:'), $email, '', '', $attremail), + '$email_hidden' => (($attremail) ? $email : ''), + '$removeme' => t('Remove Account'), + '$removeaccount' => t('Remove this account including all its channels'), '$account_settings' => $account_settings )); return $o; -- cgit v1.2.3 From 7d4bcc2e8bb8e91d5bbb2c4cf3c10555ebda0bca Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 4 Jan 2023 20:20:14 +0000 Subject: translateable strings --- Zotlabs/Widget/Channel_activities.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Widget/Channel_activities.php b/Zotlabs/Widget/Channel_activities.php index 9acde591d..06080f8c8 100644 --- a/Zotlabs/Widget/Channel_activities.php +++ b/Zotlabs/Widget/Channel_activities.php @@ -26,7 +26,7 @@ class Channel_activities { self::$channel = App::get_channel(); $o = '
'; - $o .= '

Welcome ' . self::$channel['channel_name'] . '!

'; + $o .= '

' . t('Welcome') . ' ' . self::$channel['channel_name'] . '!

'; //$o .= 'Last login date: ' . get_pconfig(self::$uid, 'system', 'stored_login_date') . ' from ' . get_pconfig(self::$uid, 'system', 'stored_login_addr'); self::get_photos_activity(); @@ -43,7 +43,7 @@ class Channel_activities { call_hooks('channel_activities_widget', $hookdata); if (!$hookdata['activities']) { - $o .= '

No recent activity to display

'; + $o .= '

' . t('No recent activities') . '

'; $o .= '
'; return $o; } -- cgit v1.2.3 From 23828f53bcd762f778b97c57a6d29ab59e83082d Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 5 Jan 2023 10:29:42 +0100 Subject: pubstream: when going to conv from unthreaded mode stay in the module --- Zotlabs/Module/Pubstream.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Pubstream.php b/Zotlabs/Module/Pubstream.php index 7b8d75727..9d3a4f92b 100644 --- a/Zotlabs/Module/Pubstream.php +++ b/Zotlabs/Module/Pubstream.php @@ -40,7 +40,8 @@ class Pubstream extends \Zotlabs\Web\Controller { $site_firehose = ((intval(get_config('system','site_firehose',0))) ? true : false); - $mid = ((x($_REQUEST, 'mid')) ? unpack_link_id($_REQUEST['mid']) : ''); + $mid = (($_REQUEST['mid']) ? unpack_link_id($_REQUEST['mid']) : ''); + if ($mid === false) { notice(t('Malformed message id.') . EOL); return; @@ -261,7 +262,6 @@ class Pubstream extends \Zotlabs\Web\Controller { ); - // use effective_uid param of xchan_query to help sort out comment permission // for sys_channel owned items. @@ -277,8 +277,7 @@ class Pubstream extends \Zotlabs\Web\Controller { } - // fake it - $mode = (($hashtags) ? 'search' : 'pubstream'); + $mode = (($hashtags) ? 'pubstream-new' : 'pubstream'); $o .= conversation($items,$mode,$update,$page_mode); -- cgit v1.2.3 From c95ef1a5c0c4a144f016cfc66faae17a853f78e7 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 5 Jan 2023 11:06:19 +0100 Subject: pdledit_gui: only show installed modules and widgets --- Zotlabs/Module/Pdledit_gui.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Module/Pdledit_gui.php b/Zotlabs/Module/Pdledit_gui.php index dadb3296e..45a06c00a 100644 --- a/Zotlabs/Module/Pdledit_gui.php +++ b/Zotlabs/Module/Pdledit_gui.php @@ -6,6 +6,7 @@ use App; use Zotlabs\Web\Controller; use Zotlabs\Render\Comanche; use Zotlabs\Lib\Libsync; +use Zotlabs\Lib\Apps; class Pdledit_gui extends Controller { @@ -241,6 +242,10 @@ class Pdledit_gui extends Controller { $addons = plugins_installed_list(); if ($addons) { foreach ($addons as $name) { + if (!Apps::addon_app_installed(local_channel(), $name)) { + continue; + } + $path = 'addon/' . $name . '/mod_' . $name . '.pdl'; if (file_exists($path)) { $arr[] = $name; @@ -270,8 +275,11 @@ class Pdledit_gui extends Controller { if ($addons) { foreach ($addons as $name) { - $path = 'addon/' . $name . '/Widget'; + if (!Apps::addon_app_installed(local_channel(), $name)) { + continue; + } + $path = 'addon/' . $name . '/Widget'; if (is_dir($path)) { $checkpaths[] = $path . '/*.php'; } -- cgit v1.2.3 From 47071c58aa868ee9756a98c967b64c024d22920b Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 5 Jan 2023 18:21:49 +0100 Subject: fix affinity slider updates - issue #1714 --- Zotlabs/Web/Session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Web/Session.php b/Zotlabs/Web/Session.php index 14c054d20..1b5537ba0 100644 --- a/Zotlabs/Web/Session.php +++ b/Zotlabs/Web/Session.php @@ -81,7 +81,7 @@ class Session { 'lifetime' => ((isset($arr['lifetime'])) ? $arr['lifetime'] : 0), 'path' => ((isset($arr['path'])) ? $arr['path'] : '/'), 'domain' => (($arr['domain']) ? $arr['domain'] : false), - 'secure' => ((isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') ? true : false), + 'secure' => true, //((isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') ? true : false), 'httponly' => ((isset($arr['httponly'])) ? $arr['httponly'] : true), 'samesite' => 'None' ]); -- cgit v1.2.3 From b40499b4c13c3ebfe99181362c1888cc78ccff3a Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 5 Jan 2023 18:25:08 +0100 Subject: revert accidental change in session --- Zotlabs/Web/Session.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Web/Session.php b/Zotlabs/Web/Session.php index 1b5537ba0..14c054d20 100644 --- a/Zotlabs/Web/Session.php +++ b/Zotlabs/Web/Session.php @@ -81,7 +81,7 @@ class Session { 'lifetime' => ((isset($arr['lifetime'])) ? $arr['lifetime'] : 0), 'path' => ((isset($arr['path'])) ? $arr['path'] : '/'), 'domain' => (($arr['domain']) ? $arr['domain'] : false), - 'secure' => true, //((isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') ? true : false), + 'secure' => ((isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) == 'on') ? true : false), 'httponly' => ((isset($arr['httponly'])) ? $arr['httponly'] : true), 'samesite' => 'None' ]); -- cgit v1.2.3 From 16555b93bbe4ef69dbbce8085bb366134f8a5654 Mon Sep 17 00:00:00 2001 From: Mario Date: Wed, 11 Jan 2023 16:34:23 +0000 Subject: fix race conditions when processing multiple choice polls --- Zotlabs/Lib/Activity.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 8f4e0444c..4a14b1ba1 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2081,16 +2081,29 @@ class Activity { } - static function update_poll($item, $post) { + static function update_poll($item_id, $post) { $multi = false; $mid = $post['mid']; $content = $post['title']; + if (!$item_id) { + return false; + } + + dbq("START TRANSACTION"); + + $item = q("SELECT * FROM item WHERE id = %d FOR UPDATE", + intval($item_id) + ); + if (!$item) { + dbq("COMMIT"); return false; } + $item = $item[0]; + $o = json_decode($item['obj'], true); if ($o && array_key_exists('anyOf', $o)) { $multi = true; @@ -2162,16 +2175,23 @@ class Activity { } logger('updated_poll: ' . print_r($o, true), LOGGER_DATA); if ($answer_found && !$found) { - q("update item set obj = '%s', edited = '%s' where id = %d", + $u = q("update item set obj = '%s', edited = '%s' where id = %d", dbesc(json_encode($o)), dbesc(datetime_convert()), intval($item['id']) ); - Master::Summon(['Notifier', 'wall-new', $item['id'], $post['mid'] /* trick queueworker de-duplication */ ]); - return true; + if ($u) { + dbq("COMMIT"); + Master::Summon(['Notifier', 'wall-new', $item['id']/* , $post['mid'] trick queueworker de-duplication */ ]); + return true; + } + + dbq("ROLLBACK"); + } + dbq("COMMIT"); return false; } -- cgit v1.2.3 From d092e79ebcfd34c71cc50f2d676eb097482e4d91 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 12 Jan 2023 11:04:03 +0000 Subject: remove fragment in notifier - it should not be required, when processing multiple choice polls sleep some time before calling the notifier --- Zotlabs/Daemon/Notifier.php | 10 ++-------- Zotlabs/Lib/Activity.php | 9 ++++++++- 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Daemon/Notifier.php b/Zotlabs/Daemon/Notifier.php index f51dfab28..de8597081 100644 --- a/Zotlabs/Daemon/Notifier.php +++ b/Zotlabs/Daemon/Notifier.php @@ -79,10 +79,7 @@ class Notifier { static public $encoded_item = null; static public $channel = null; static public $private = false; - // $fragment can contain additional info to omit de-duplication in the queueworker. - // E.g. if an item is updated many times in a row from different sources (multiple vote updates) the - // update source mid or a timestamp or random string can be added. - static public $fragment = null; + static public function run($argc, $argv) { @@ -107,7 +104,6 @@ class Notifier { self::$encoded_item = null; self::$channel = null; self::$private = false; - self::$fragment = null; $sys = get_sys_channel(); $normal_mode = true; @@ -233,8 +229,6 @@ class Notifier { // Fetch the target item - self::$fragment = $argv[3] ?? ''; - $r = q("SELECT * FROM item WHERE id = %d AND parent != 0", intval($item_id) ); @@ -701,7 +695,7 @@ class Notifier { // This wastes a process if there are no delivery hooks configured, so check this before launching the new process $x = q("select * from hook where hook = 'notifier_normal'"); if ($x) { - Master::Summon(['Deliver_hooks', $target_item['id'], self::$fragment]); + Master::Summon(['Deliver_hooks', $target_item['id']]); } } diff --git a/Zotlabs/Lib/Activity.php b/Zotlabs/Lib/Activity.php index 4a14b1ba1..1a1031909 100644 --- a/Zotlabs/Lib/Activity.php +++ b/Zotlabs/Lib/Activity.php @@ -2183,7 +2183,14 @@ class Activity { if ($u) { dbq("COMMIT"); - Master::Summon(['Notifier', 'wall-new', $item['id']/* , $post['mid'] trick queueworker de-duplication */ ]); + + if ($multi) { + // wait some seconds for possible multiple answers to be processed + // before calling the notifier + sleep(3); + } + + Master::Summon(['Notifier', 'wall-new', $item['id']]); return true; } -- cgit v1.2.3 From 8a7b22141239969b3af39582019dfa455612bb41 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 12 Jan 2023 11:28:48 +0000 Subject: mark old hubloc entries from re-installed hubs deleted if we discover any --- Zotlabs/Lib/Libsync.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'Zotlabs') diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php index f844c63b5..19361c4ae 100644 --- a/Zotlabs/Lib/Libsync.php +++ b/Zotlabs/Lib/Libsync.php @@ -862,7 +862,9 @@ class Libsync { ); } - // update connection timestamp if this is the site we're talking to + // Update connection timestamp if this is the site we're talking to. + // Also mark all entries from the current site with different sitekeys + // deleted (the site has been re-installed) // This only happens when called from import_xchan $current_site = false; @@ -876,6 +878,12 @@ class Libsync { intval($r[0]['hubloc_id']), dbesc($t) ); + + q("update hubloc set hubloc_error = 1, hubloc_deleted = 1 where hubloc_url = '%s' and hubloc_sitekey != '%s'", + dbesc($r[0]['hubloc_url']), + dbesc($r[0]['hubloc_sitekey']) + ); + $current_site = true; } -- cgit v1.2.3