provide a site-wide expiration policy without loopholes - still need work to reduce the impact of expiration queries.

This commit is contained in:
friendica 2015-03-24 15:53:55 -07:00
parent abf642be7f
commit 3d60008842
3 changed files with 30 additions and 12 deletions

View File

@ -7,7 +7,11 @@ function expire_run($argv, $argc){
cli_startup(); cli_startup();
$r = q("select id from item where (item_restrict & %d)>0 and not (item_restrict & %d)>0 and changed < %s - INTERVAL %s",
// perform final cleanup on previously delete items
$r = q("select id from item where (item_restrict & %d) > 0 and (item_restrict & %d) = 0
and changed < %s - INTERVAL %s",
intval(ITEM_DELETED), intval(ITEM_DELETED),
intval(ITEM_PENDING_REMOVE), intval(ITEM_PENDING_REMOVE),
db_utcnow(), db_quoteinterval('10 DAY') db_utcnow(), db_quoteinterval('10 DAY')
@ -19,8 +23,9 @@ function expire_run($argv, $argc){
} }
// physically remove anything that has been deleted for more than two months // physically remove anything that has been deleted for more than two months
// FIXME - this is a wretchedly inefficient query
$r = q("delete from item where ( item_restrict & %d )>0 and changed < %s - INTERVAL %s", $r = q("delete from item where ( item_restrict & %d ) > 0 and changed < %s - INTERVAL %s",
intval(ITEM_PENDING_REMOVE), intval(ITEM_PENDING_REMOVE),
db_utcnow(), db_quoteinterval('36 DAY') db_utcnow(), db_quoteinterval('36 DAY')
); );
@ -32,12 +37,28 @@ function expire_run($argv, $argc){
logger('expire: start', LOGGER_DEBUG); logger('expire: start', LOGGER_DEBUG);
$site_expire = get_config('system', 'default_expire_days');
if(intval($site_expire)) {
$r = q("SELECT channel_id, channel_address, channel_pageflags, channel_expire_days from channel where true");
}
else {
$r = q("SELECT channel_id, channel_address, channel_pageflags, channel_expire_days from channel where channel_expire_days != 0");
}
$r = q("SELECT channel_id, channel_address, channel_expire_days from channel where channel_expire_days != 0"); if($r) {
if($r && count($r)) {
foreach($r as $rr) { foreach($r as $rr) {
// expire the sys channel separately
if($rr['channel_pageflags'] & PAGE_SYSTEM)
continue;
// if the site expiration is non-zero and less than person expiration, use that
logger('Expire: ' . $rr['channel_address'] . ' interval: ' . $rr['channel_expire_days'], LOGGER_DEBUG); logger('Expire: ' . $rr['channel_address'] . ' interval: ' . $rr['channel_expire_days'], LOGGER_DEBUG);
item_expire($rr['channel_id'],$rr['channel_expire_days']); item_expire($rr['channel_id'],
((intval($site_expire) && intval($site_expire) < intval($rr['channel_expire_days']))
? $site_expire
: $rr['channel_expire_days'])
);
} }
} }
@ -48,14 +69,13 @@ function expire_run($argv, $argc){
// this should probably just fetch the channel_expire_days from the sys channel, // this should probably just fetch the channel_expire_days from the sys channel,
// but there's no convenient way to set it. // but there's no convenient way to set it.
$expire_days = get_config('externals','expire_days'); $expire_days = get_config('system','sys_expire_days');
if($expire_days === false) if($expire_days === false)
$expire_days = 30; $expire_days = 30;
if($expire_days) if($expire_days)
item_expire($x['channel_id'],$expire_days); item_expire($x['channel_id'],(($site_expire && $site_expire < $expire_days) ? $site_expire : $expire_days));
} }
return; return;
} }

View File

@ -249,9 +249,7 @@ function create_identity($arr) {
} }
} }
$expire = 0;
$expire = get_config('system', 'default_expire_days');
$expire = (($expire===false)? '0': $expire);
$r = q("insert into channel ( channel_account_id, channel_primary, $r = q("insert into channel ( channel_account_id, channel_primary,
channel_name, channel_address, channel_guid, channel_guid_sig, channel_name, channel_address, channel_guid, channel_guid_sig,

View File

@ -3922,7 +3922,7 @@ function item_expire($uid,$days) {
$expire_network_only = 1; $expire_network_only = 1;
$sql_extra = ((intval($expire_network_only)) ? " AND not (item_flags & " . intval(ITEM_WALL) . ")>0 " : ""); $sql_extra = ((intval($expire_network_only)) ? " AND not (item_flags & " . intval(ITEM_WALL) . ") > 0 " : "");
$r = q("SELECT * FROM `item` $r = q("SELECT * FROM `item`
WHERE `uid` = %d WHERE `uid` = %d