`language` varchar(32) NOT NULL DEFAULT 'en' COMMENT 'default language',
`register_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of registration',
`login_date` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT 'timestamp of last login',
+ `last-activity` date COMMENT 'Day of the last activity',
`default-location` varchar(255) NOT NULL DEFAULT '' COMMENT 'Default for item.location',
`allow_location` boolean NOT NULL DEFAULT '0' COMMENT '1 allows to display the location',
`theme` varchar(255) NOT NULL DEFAULT '' COMMENT 'user theme preference',
| language | default language | varchar(32) | NO | | en | |
| register_date | timestamp of registration | datetime | NO | | 0001-01-01 00:00:00 | |
| login_date | timestamp of last login | datetime | NO | | 0001-01-01 00:00:00 | |
+| last-activity | Day of the last activity | date | YES | | NULL | |
| default-location | Default for item.location | varchar(255) | NO | | | |
| allow_location | 1 allows to display the location | boolean | NO | | 0 | |
| theme | user theme preference | varchar(255) | NO | | | |
return true;
}
+ /**
+ * Check if the cached suggestion is outdated
+ *
+ * @param integer $uid
+ * @return boolean
+ */
+ static public function areSuggestionsOutdated(int $uid): bool
+ {
+ return DI::pConfig()->get($uid, 'suggestion', 'last_update') + 3600 < time();
+ }
+
/**
* Update contact suggestions for a given user
*
*/
static public function updateCachedSuggestions(int $uid)
{
- if (DI::pConfig()->get($uid, 'suggestion', 'last_update') + 3600 > time()) {
+ if (!self::areSuggestionsOutdated($uid)) {
return;
}
return $user;
}
+ /**
+ * Update the day of the last activity of the given user
+ *
+ * @param integer $uid
+ * @return void
+ */
+ public static function updateLastActivity(int $uid)
+ {
+ $user = User::getById($uid, ['last-activity']);
+ $current_day = date('Y-m-d');
+
+ if ($user['last-activity'] != $current_day) {
+ User::update(['last-activity' => $current_day], $uid);
+ }
+ }
+
/**
* Generates a human-readable random password
*
use LightOpenID;
use Friendica\Core\L10n;
use Friendica\Core\Worker;
+use Friendica\Model\Contact;
use Psr\Log\LoggerInterface;
/**
$this->dba->update('user', ['login_date' => DateTimeFormat::utcNow()],
['parent-uid' => $user_record['uid'], 'account_removed' => false]);
- // Update suggestions upon login
- Worker::add(Worker::PRIORITY_MEDIUM, 'UpdateSuggestions', $user_record['uid']);
+ User::updateLastActivity($user_record['uid']);
+
+ // Regularly update suggestions
+ if (Contact\Relation::areSuggestionsOutdated($user_record['uid'])) {
+ Worker::add(Worker::PRIORITY_MEDIUM, 'UpdateSuggestions', $user_record['uid']);
+ }
}
if ($login_initial) {
namespace Friendica\Security;
use Friendica\Core\Logger;
+use Friendica\Core\Worker;
use Friendica\Database\Database;
use Friendica\Database\DBA;
+use Friendica\Model\Contact;
+use Friendica\Model\User;
use Friendica\Module\BaseApi;
use Friendica\Util\DateTimeFormat;
return [];
}
Logger::debug('Token found', $token);
+
+ User::updateLastActivity($token['uid']);
+
+ // Regularly update suggestions
+ if (Contact\Relation::areSuggestionsOutdated($token['uid'])) {
+ Worker::add(Worker::PRIORITY_MEDIUM, 'UpdateSuggestions', $token['uid']);
+ }
+
return $token;
}
{
public static function execute()
{
- $users = DBA::select('user', ['uid'], ["`login_date` > ?", DateTimeFormat::utc('now - 7 days')]);
+ $users = DBA::select('user', ['uid'], ["`last-activity` > ?", DateTimeFormat::utc('now - 3 days', 'Y-m-d')]);
while ($user = DBA::fetch($users)) {
Contact\Relation::updateCachedSuggestions($user['uid']);
}
"language" => ["type" => "varchar(32)", "not null" => "1", "default" => "en", "comment" => "default language"],
"register_date" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "timestamp of registration"],
"login_date" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => "timestamp of last login"],
+ "last-activity" => ["type" => "date", "comment" => "Day of the last activity"],
"default-location" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "Default for item.location"],
"allow_location" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => "1 allows to display the location"],
"theme" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => "user theme preference"],