improved item_expire()

This commit is contained in:
Mario Vavti
2023-04-14 09:21:33 +02:00
parent 20f4538db4
commit d8811b499d
4 changed files with 34 additions and 40 deletions

View File

@@ -32,7 +32,6 @@ class Expire {
}
// physically remove anything that has been deleted for more than two months
/** @FIXME - this is a wretchedly inefficient query */
q("delete from item where item_pending_remove = 1 and changed < %s - INTERVAL %s",
db_utcnow(),
@@ -59,8 +58,8 @@ class Expire {
continue;
// service class default (if non-zero) over-rides the site default
$service_class_expire = service_class_fetch($rr['channel_id'], 'expire_days');
if (intval($service_class_expire))
$channel_expire = $service_class_expire;
else
@@ -85,7 +84,6 @@ class Expire {
// this should probably just fetch the channel_expire_days from the sys channel,
// but there's no convenient way to set it.
$expire_days = get_config('system', 'sys_expire_days');
if ($expire_days === false)
$expire_days = 30;
@@ -96,8 +94,9 @@ class Expire {
logger('Expire: sys interval: ' . $expire_days, LOGGER_DEBUG);
if ($expire_days)
if ($expire_days) {
item_expire($x['channel_id'], $expire_days, $commented_days);
}
logger('Expire: sys: done', LOGGER_DEBUG);
}

View File

@@ -24,7 +24,8 @@ class QueueWorker {
// Exceptions for processtimeout ($workermaxage) value.
// Currently the value is overriden with 3600 seconds (1h).
public static $long_running_cmd = [
'Queue'
'Queue',
'Expire'
];
private static function qstart() {
@@ -147,6 +148,10 @@ class QueueWorker {
);
if ($r) {
// TODO: some long running services store their pid in config.procid.daemon
// we could possibly check if a pid exist and check if the process is still alive
// prior to reseting workerq_reservationid
$ids = ids_to_querystr($r, 'workerq_id');
$u = dbq("update workerq set workerq_reservationid = null where workerq_id in ($ids)");
}

View File

@@ -1117,6 +1117,7 @@ function account_service_class_allows($aid, $property, $usage = false) {
*/
function service_class_fetch($uid, $property) {
$service_class = null;
if($uid == local_channel()) {
$service_class = App::$account['account_service_class'];
@@ -1127,7 +1128,7 @@ function service_class_fetch($uid, $property) {
where c.channel_account_id=a.account_id and c.channel_id= %d limit 1",
intval($uid)
);
if($r !== false and count($r)) {
if($r) {
$service_class = $r[0]['service_class'];
}
}
@@ -1161,7 +1162,7 @@ function account_service_class_fetch($aid, $property) {
$r = q("select account_service_class as service_class from account where account_id = %d limit 1",
intval($aid)
);
if($r !== false && count($r)) {
if($r) {
$service_class = $r[0]['service_class'];
}

View File

@@ -3755,45 +3755,34 @@ function item_expire($uid,$days,$comment_days = 7) {
$sql_extra = ((intval($expire_network_only)) ? " AND item_wall = 0 " : "");
$expire_limit = get_config('system','expire_limit');
if(! intval($expire_limit))
$expire_limit = 5000;
$expire_limit = get_config('system','expire_limit', 1000);
$item_normal = item_normal();
$r = q("SELECT id FROM item
WHERE uid = %d
AND created < %s - INTERVAL %s
AND commented < %s - INTERVAL %s
AND item_retained = 0
AND item_thread_top = 1
AND resource_type = ''
AND item_starred = 0
$sql_extra $item_normal LIMIT $expire_limit ",
intval($uid),
db_utcnow(),
db_quoteinterval(intval($days) . ' DAY'),
db_utcnow(),
db_quoteinterval(intval($comment_days) . ' DAY')
);
do {
$r = q("SELECT id FROM item
WHERE uid = %d
AND created < %s - INTERVAL %s
AND commented < %s - INTERVAL %s
AND item_retained = 0
AND item_thread_top = 1
AND resource_type = ''
AND item_starred = 0
$sql_extra $item_normal LIMIT $expire_limit",
intval($uid),
db_utcnow(),
db_quoteinterval(intval($days) . ' DAY'),
db_utcnow(),
db_quoteinterval(intval($comment_days) . ' DAY')
);
if(! $r)
return;
$r = fetch_post_tags($r,true);
foreach($r as $item) {
// don't expire filed items
if (isset($item['term']) && get_terms_oftype($item['term'], TERM_FILE)) {
retain_item($item['id']);
continue;
if ($r) {
foreach ($r as $item) {
drop_item($item['id'], false);
}
}
drop_item($item['id'],false);
}
} while ($r);
}
function retain_item($id) {