From 63b8020969434756a7b966ae615c28bf7680f2f8 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 24 Mar 2015 17:09:42 -0700 Subject: more work on expiration, make system limits useful - even in retrospect --- doc/hidden_configs.bb | 5 ++++- include/expire.php | 34 +++++++++++++++++++++++++--------- include/items.php | 6 +++++- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/doc/hidden_configs.bb b/doc/hidden_configs.bb index ea945f8d2..c6181b9dd 100644 --- a/doc/hidden_configs.bb +++ b/doc/hidden_configs.bb @@ -89,8 +89,11 @@ This document assumes you're an administrator. There also exist CLI utilities for performing this operation, which you may prefer, especially if you're a large site. [b]system > default_expire_days[/b] - When creating a new channel, set the default expiration of connections + set the default expiration of connections' (matrix/network) posts to this number of days. + [b]system > expire_limit + Don't expire any more than this number of posts per channel per + expiration run to keep from exhausting memory. Default 5000. [b]system > dlogfile[/b] Logfile to use for logging development errors. Exactly the same as logger otherwise. This isn't magic, and requires your own logging diff --git a/include/expire.php b/include/expire.php index 9ef0f7b69..e414a6e7d 100644 --- a/include/expire.php +++ b/include/expire.php @@ -38,6 +38,9 @@ function expire_run($argv, $argc){ logger('expire: start', LOGGER_DEBUG); $site_expire = get_config('system', 'default_expire_days'); + + logger('site_expire: ' . $site_expire); + if(intval($site_expire)) { $r = q("SELECT channel_id, channel_address, channel_pageflags, channel_expire_days from channel where true"); } @@ -52,15 +55,18 @@ function expire_run($argv, $argc){ if($rr['channel_pageflags'] & PAGE_SYSTEM) continue; + if(intval($site_expire) && (intval($site_expire) < intval($rr['channel_expire_days'])) || + intval($rr['channel_expire_days'] == 0)) { + $expire_days = $site_expire; + } + else { + $expire_days = $rr['channel_expire_days']; + } + + // if the site expiration is non-zero and less than person expiration, use that - logger('Expire: ' . $rr['channel_address'] . ' interval: ' . ((intval($site_expire) && intval($site_expire) < intval($rr['channel_expire_days'])) - ? $site_expire - : $rr['channel_expire_days']), LOGGER_DEBUG); - item_expire($rr['channel_id'], - ((intval($site_expire) && intval($site_expire) < intval($rr['channel_expire_days'])) - ? $site_expire - : $rr['channel_expire_days']) - ); + logger('Expire: ' . $rr['channel_address'] . ' interval: ' . $expire_days, LOGGER_DEBUG); + item_expire($rr['channel_id'], $expire_days); } } @@ -74,8 +80,18 @@ function expire_run($argv, $argc){ $expire_days = get_config('system','sys_expire_days'); if($expire_days === false) $expire_days = 30; + + if(intval($site_expire) && (intval($site_expire) < intval($expire_days))) { + $expire_days = $site_expire; + } + + logger('Expire: sys interval: ' . $expire_days, LOGGER_DEBUG); + if($expire_days) - item_expire($x['channel_id'],(($site_expire && $site_expire < $expire_days) ? $site_expire : $expire_days)); + item_expire($x['channel_id'],$expire_days); + + logger('Expire: sys: done', LOGGER_DEBUG); + } return; diff --git a/include/items.php b/include/items.php index a1515ad88..da0e50c4c 100755 --- a/include/items.php +++ b/include/items.php @@ -3922,6 +3922,10 @@ function item_expire($uid,$days) { $expire_network_only = 1; + $expire_limit = get_config('system','expire_limit'); + if(! intval($expire_limit)) + $expire_limit = 5000; + $sql_extra = ((intval($expire_network_only)) ? " AND not (item_flags & " . intval(ITEM_WALL) . ") > 0 " : ""); $r = q("SELECT * FROM `item` @@ -3930,7 +3934,7 @@ function item_expire($uid,$days) { AND `id` = `parent` $sql_extra AND NOT ( item_flags & %d )>0 - AND (item_restrict = 0 ) ", + AND (item_restrict = 0 ) LIMIT $expire_limit ", intval($uid), db_utcnow(), db_quoteinterval(intval($days).' DAY'), intval(ITEM_RETAINED) -- cgit v1.2.3