From f277d08244986c080d48af3e8bc86a9886d098bc Mon Sep 17 00:00:00 2001 From: Mario Date: Fri, 21 Apr 2023 07:45:32 +0000 Subject: queue and poller testing --- Zotlabs/Daemon/Onepoll.php | 12 ++++-------- Zotlabs/Daemon/Poller.php | 7 ++++++- Zotlabs/Daemon/Queue.php | 17 +++++++++-------- Zotlabs/Lib/Libsync.php | 2 +- Zotlabs/Lib/Queue.php | 24 +++++------------------- 5 files changed, 25 insertions(+), 37 deletions(-) diff --git a/Zotlabs/Daemon/Onepoll.php b/Zotlabs/Daemon/Onepoll.php index bde39007e..973bcf402 100644 --- a/Zotlabs/Daemon/Onepoll.php +++ b/Zotlabs/Daemon/Onepoll.php @@ -30,14 +30,10 @@ class Onepoll { $sql_extra = ' and abook_feed = 0 '; } - $contacts = q("SELECT abook.*, xchan.*, account.* - FROM abook LEFT JOIN account on abook_account = account_id left join xchan on xchan_hash = abook_xchan - where abook_id = %d $sql_extra - and abook_pending = 0 and abook_archived = 0 and abook_blocked = 0 and abook_ignored = 0 - AND (( account_flags = %d ) OR ( account_flags = %d )) limit 1", - intval($contact_id), - intval(ACCOUNT_OK), - intval(ACCOUNT_UNVERIFIED) + $contacts = q("SELECT abook.*, xchan.* FROM abook + LEFT JOIN xchan ON xchan_hash = abook_xchan + WHERE abook_id = %d", + intval($contact_id) ); if (!$contacts) { diff --git a/Zotlabs/Daemon/Poller.php b/Zotlabs/Daemon/Poller.php index 9e47a5e77..b6b52af81 100644 --- a/Zotlabs/Daemon/Poller.php +++ b/Zotlabs/Daemon/Poller.php @@ -49,6 +49,11 @@ class Poller { : '' ); + $allow_feeds = get_config('system', 'feed_contacts'); + if(!$allow_feeds) { + $sql_extra .= ' and abook_feed = 0 '; + } + $randfunc = db_getfunc('RAND'); $contacts = q("SELECT abook.abook_updated, abook.abook_connected, abook.abook_feed, @@ -58,7 +63,7 @@ class Poller { account.account_lastlog, account.account_flags FROM abook LEFT JOIN xchan on abook_xchan = xchan_hash LEFT JOIN account on abook_account = account_id - where abook_self = 0 + where abook_self = 0 and abook_pending = 0 and abook_archived = 0 and abook_blocked = 0 and abook_ignored = 0 $sql_extra AND (( account_flags = %d ) OR ( account_flags = %d )) $abandon_sql ORDER BY $randfunc", intval(ACCOUNT_OK), diff --git a/Zotlabs/Daemon/Queue.php b/Zotlabs/Daemon/Queue.php index b07fe369c..91aba831a 100644 --- a/Zotlabs/Daemon/Queue.php +++ b/Zotlabs/Daemon/Queue.php @@ -14,7 +14,7 @@ class Queue { // delete all queue items more than 3 days old // but first mark these sites dead if we haven't heard from them in a month - $oldqItems = q("select outq_posturl from outq where outq_created < %s - INTERVAL %s", + $oldqItems = q("select outq_posturl, outq_hash from outq where outq_created < %s - INTERVAL %s", db_utcnow(), db_quoteinterval('3 DAY') ); @@ -29,13 +29,13 @@ class Queue { db_quoteinterval('1 MONTH') ); } - } - logger('Removing ' . count($oldqItems) . ' old queue entries'); - q("DELETE FROM outq WHERE outq_created < %s - INTERVAL %s", - db_utcnow(), - db_quoteinterval('3 DAY') - ); + $old_hashes = ids_to_querystr($oldqItems, 'outq_hash', true); + + logger('Removing ' . count($oldqItems) . ' old queue entries'); + dbq("DELETE FROM outq WHERE outq_hash IN ($old_hashes)"); + + } $deliveries = []; @@ -47,9 +47,10 @@ class Queue { LibQueue::deliver($qItems[0]); } else { - $qItems = q("SELECT * FROM outq WHERE outq_delivered = 0 and outq_scheduled < %s ", + $qItems = q("SELECT outq_hash FROM outq WHERE outq_scheduled < %s ", db_utcnow() ); + if ($qItems) { foreach ($qItems as $qItem) { $deliveries[] = $qItem['outq_hash']; diff --git a/Zotlabs/Lib/Libsync.php b/Zotlabs/Lib/Libsync.php index 84117abb0..0d383c697 100644 --- a/Zotlabs/Lib/Libsync.php +++ b/Zotlabs/Lib/Libsync.php @@ -141,7 +141,7 @@ class Libsync { $total = count($synchubs); foreach ($synchubs as $hub) { - $hash = random_string(); + $hash = new_uuid(); $n = Libzot::build_packet($channel, 'sync', $env_recips, json_encode($info), 'hz', $hub['hubloc_sitekey'], $hub['site_crypto']); Queue::insert([ 'hash' => $hash, diff --git a/Zotlabs/Lib/Queue.php b/Zotlabs/Lib/Queue.php index 348a2a079..942a633ef 100644 --- a/Zotlabs/Lib/Queue.php +++ b/Zotlabs/Lib/Queue.php @@ -57,7 +57,6 @@ class Queue { outq_priority = outq_priority + %d, outq_scheduled = '%s' WHERE outq_hash = '%s'", - dbesc(datetime_convert()), intval($add_priority), dbesc($next), @@ -85,29 +84,16 @@ class Queue { // entries still exist for it. This fixes an issue where one immediate delivery left everything // else for that site undeliverable since all the other entries had been pushed far into the future. - $x = null; - $sql_quirks = ((get_config('system', 'db_skip_locked_supported')) ? 'SKIP LOCKED' : 'NOWAIT'); - - q("START TRANSACTION"); - - $r = q("SELECT outq_hash FROM outq WHERE outq_posturl = '%s' LIMIT 1 FOR UPDATE $sql_quirks", + $r = q("SELECT outq_hash, outq_posturl FROM outq WHERE outq_posturl = '%s' LIMIT 1", dbesc($record[0]['outq_posturl']) ); if ($r) { - $x = q("UPDATE outq SET outq_scheduled = '%s' WHERE outq_hash = '%s'", - dbesc(datetime_convert()), - dbesc($r[0]['outq_hash']) + $hashes = ids_to_querystr($r, 'outq_hash', true); + $x = q("UPDATE outq SET outq_scheduled = '%s' WHERE outq_hash IN ($hashes)", + dbesc(datetime_convert()) ); } - - if ($x) { - q("COMMIT"); - } - else { - q("ROLLBACK"); - } - } } @@ -260,7 +246,7 @@ class Queue { if($result['success']) { logger('deliver: remote zot delivery succeeded to ' . $outq['outq_posturl']); - Libzot::process_response($outq['outq_posturl'],$result, $outq); + Libzot::process_response($outq['outq_posturl'], $result, $outq); } else { logger('deliver: remote zot delivery failed to ' . $outq['outq_posturl']); -- cgit v1.2.3