Simplify "last-activity" handling

This commit is contained in:
Michael 2022-12-04 07:17:26 +00:00
parent 1d8c9276f3
commit e5a531d3b5
5 changed files with 12 additions and 15 deletions

View File

@ -2693,7 +2693,7 @@ CREATE VIEW `owner-view` AS SELECT
`user`.`language` AS `language`, `user`.`language` AS `language`,
`user`.`register_date` AS `register_date`, `user`.`register_date` AS `register_date`,
`user`.`login_date` AS `login_date`, `user`.`login_date` AS `login_date`,
IF (`user`.`last-activity` IS NULL, DATE(`user`.`login_date`), `user`.`last-activity`) AS `last-activity`, `user`.`last-activity` AS `last-activity`,
`user`.`default-location` AS `default-location`, `user`.`default-location` AS `default-location`,
`user`.`allow_location` AS `allow_location`, `user`.`allow_location` AS `allow_location`,
`user`.`theme` AS `theme`, `user`.`theme` AS `theme`,

View File

@ -94,18 +94,9 @@ class NoScrape extends BaseModule
} }
// We display the last activity (post or login), reduced to year and week number // We display the last activity (post or login), reduced to year and week number
$last_active = 0; $last_active = strtotime($owner['last-item']);
$condition = ['uid' => $owner['uid'], 'self' => true]; if ($last_active < strtotime($owner['last-activity'])) {
$contact = DBA::selectFirst('contact', ['last-item'], $condition); $last_active = strtotime($owner['last-activity']);
if (DBA::isResult($contact)) {
$last_active = strtotime($contact['last-item']);
}
$user = User::getOwnerDataById($owner['uid']);
if (DBA::isResult($user)) {
if ($last_active < strtotime($user['last-activity'])) {
$last_active = strtotime($user['last-activity']);
}
} }
$json_info['last-activity'] = date('o-W', $last_active); $json_info['last-activity'] = date('o-W', $last_active);

View File

@ -45,7 +45,7 @@ class PollContacts
if (!empty($abandon_days)) { if (!empty($abandon_days)) {
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition,
["`uid` != ? AND `uid` IN (SELECT `uid` FROM `owner-view` WHERE NOT `account_expired` AND NOT `account_removed` AND `last-activity` > ?)", 0, DateTimeFormat::utc('now - ' . $abandon_days . ' days')]); ["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE NOT `account_expired` AND NOT `account_removed` AND `last-activity` > ?)", 0, DateTimeFormat::utc('now - ' . $abandon_days . ' days')]);
} else { } else {
$condition = DBA::mergeConditions($condition, $condition = DBA::mergeConditions($condition,
["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE NOT `account_expired` AND NOT `account_removed`)", 0]); ["`uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE NOT `account_expired` AND NOT `account_removed`)", 0]);

View File

@ -889,7 +889,7 @@
"language" => ["user", "language"], "language" => ["user", "language"],
"register_date" => ["user", "register_date"], "register_date" => ["user", "register_date"],
"login_date" => ["user", "login_date"], "login_date" => ["user", "login_date"],
"last-activity" => "IF (`user`.`last-activity` IS NULL, DATE(`user`.`login_date`), `user`.`last-activity`)", "last-activity" => ["user", "last-activity"],
"default-location" => ["user", "default-location"], "default-location" => ["user", "default-location"],
"allow_location" => ["user", "allow_location"], "allow_location" => ["user", "allow_location"],
"theme" => ["user", "theme"], "theme" => ["user", "theme"],

View File

@ -1126,4 +1126,10 @@ function update_1491()
{ {
DBA::update('contact', ['remote_self' => Contact::MIRROR_OWN_POST], ['remote_self' => Contact::MIRROR_FORWARDED]); DBA::update('contact', ['remote_self' => Contact::MIRROR_OWN_POST], ['remote_self' => Contact::MIRROR_FORWARDED]);
return Update::SUCCESS; return Update::SUCCESS;
}
function update_1497()
{
DBA::e("UPDATE `user` SET `last-activity` = DATE(`login_date`) WHERE `last-activity` IS NULL");
return Update::SUCCESS;
} }