From 9fa929fab5c4c547951a0b42e7d56a94aea17564 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 25 May 2014 23:00:06 -0700 Subject: filter randprof results to avoid channels that are known to be deceased. --- include/Contact.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/Contact.php') diff --git a/include/Contact.php b/include/Contact.php index 540e1169d..0cd4be72c 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -510,7 +510,7 @@ function unmark_for_death($contact) { }} function random_profile() { - $r = q("select xchan_url from xchan where 1 order by rand() limit 1"); + $r = q("select xchan_url from xchan left join hubloc on hubloc_hash = xchan_hash where hubloc_connected > UTC_TIMESTAMP() - interval 30 day order by rand() limit 1"); if($r) return $r[0]['xchan_url']; return ''; -- cgit v1.2.3 From 2a6d7b6a079a565afc0200fe160cb2402ed7c0a3 Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 28 May 2014 21:42:46 -0700 Subject: cleanup dead directory entries. This was a real b#tch, so keep your eye out for issues - which you shouldn't see until next weekend when this is scheduled to run. We're only setting flags, so if anything goes wrong we should be able to recover without too much pain. --- include/Contact.php | 84 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 66 insertions(+), 18 deletions(-) (limited to 'include/Contact.php') diff --git a/include/Contact.php b/include/Contact.php index 0cd4be72c..6e12652a5 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -141,24 +141,6 @@ function abook_toggle_flag($abook,$flag) { } - - - - - - - - - - - - - - - - - - // Included here for completeness, but this is a very dangerous operation. // It is the caller's responsibility to confirm the requestor's intent and // authorisation to do this. @@ -305,6 +287,72 @@ function channel_remove($channel_id, $local = true) { } +/** + * mark any hubs "offline" that haven't been heard from in more than 30 days + * Allow them to redeem themselves if they come back later. + * Then go through all those that are newly marked and see if any other hubs + * are attached to the controlling xchan that are still alive. + * If not, they're dead (although they could come back some day). + */ + + +function mark_orphan_hubsxchans() { + + $r = q("update hubloc set hubloc_status = (hubloc_status | %d) where not (hubloc_status & %d) + and hubloc_connected < utc_timestamp() - interval 30 day", + intval(HUBLOC_OFFLINE), + intval(HUBLOC_OFFLINE) + ); + + $r = q("select hubloc_id, hubloc_hash from hubloc where (hubloc_status & %d) and not (hubloc_flags & %d)", + intval(HUBLOC_OFFLINE), + intval(HUBLOC_FLAGS_ORPHANCHECK) + ); + + if($r) { + foreach($r as $rr) { + + // see if any other hublocs are still alive for this channel + + $x = q("select * from hubloc where hubloc_hash = '%s' and not (hubloc_status & %d)", + dbesc($rr['hubloc_hash']), + intval(HUBLOC_OFFLINE) + ); + if($x) { + + // yes - if the xchan was marked as an orphan, undo it + + $y = q("update xchan set xchan_flags = (xchan_flags ^ %d) where (xchan_flags & %d) and xchan_hash = '%s' limit 1", + intval(XCHAN_FLAGS_ORPHAN), + intval(XCHAN_FLAGS_ORPHAN), + dbesc($rr['hubloc_hash']) + ); + + } + else { + + // nope - mark the xchan as an orphan + + $y = q("update xchan set xchan_flags = (xchan_flags | %d) where xchan_hash = '%s' limit 1", + intval(XCHAN_FLAGS_ORPHAN), + dbesc($rr['hubloc_hash']) + ); + } + + // mark that we've checked this entry so we don't need to do it again + + $y = q("update hubloc set hubloc_flags = (hubloc_flags | %d) where hubloc_id = %d limit 1", + intval(HUBLOC_FLAGS_ORPHANCHECK), + dbesc($rr['hubloc_id']) + ); + } + } + +} + + + + function remove_all_xchan_resources($xchan, $channel_id = 0) { if(intval($channel_id)) { -- cgit v1.2.3 From 1a58777daa0ab9394f38737a806a7a185ebceeb0 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 29 May 2014 00:55:34 -0700 Subject: this is an important bit - only mark dead hubs on directory servers. They shouldn't matter anywhere else. --- include/Contact.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include/Contact.php') diff --git a/include/Contact.php b/include/Contact.php index 6e12652a5..b4583c358 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -298,6 +298,10 @@ function channel_remove($channel_id, $local = true) { function mark_orphan_hubsxchans() { + $dirmode = intval(get_config('system','directory_mode')); + if($dirmode == DIRECTORY_MODE_NORMAL) + return; + $r = q("update hubloc set hubloc_status = (hubloc_status | %d) where not (hubloc_status & %d) and hubloc_connected < utc_timestamp() - interval 30 day", intval(HUBLOC_OFFLINE), -- cgit v1.2.3