]> git.mxchange.org Git - friendica.git/commitdiff
New field to show the day of the last activity
authorMichael <heluecht@pirati.ca>
Wed, 30 Nov 2022 22:34:50 +0000 (22:34 +0000)
committerMichael <heluecht@pirati.ca>
Wed, 30 Nov 2022 22:34:50 +0000 (22:34 +0000)
database.sql
doc/database/db_user.md
src/Model/Contact/Relation.php
src/Model/User.php
src/Security/Authentication.php
src/Security/OAuth.php
src/Worker/UpdateAllSuggestions.php
static/dbstructure.config.php

index cf07937725e165010d8d86d6899fda9c108be941..f41defe4284a1efd4f42a09adf53792e792cb897 100644 (file)
@@ -59,6 +59,7 @@ CREATE TABLE IF NOT EXISTS `user` (
        `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',
index 85fe895e98502454f67126590b863214a0fea58e..7f58ce58f1573f066db0be0f47ec0ebd5bc9ddea 100644 (file)
@@ -21,6 +21,7 @@ Fields
 | 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   |     |                     |                |
index 5a85ebebc58421032125918299ab79c7a309edd7..bae59f48c57e727df52fbc7ac53548264be3c44e 100644 (file)
@@ -260,6 +260,17 @@ class Relation
                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
         *
@@ -268,7 +279,7 @@ class Relation
         */
        static public function updateCachedSuggestions(int $uid)
        {
-               if (DI::pConfig()->get($uid, 'suggestion', 'last_update') + 3600 > time()) {
+               if (!self::areSuggestionsOutdated($uid)) {
                        return;
                }
 
index 73c380561c9c80786e5a98e8f615da7da7dced95..6d7efafb18786762c415daa763f9d9e55a97e369 100644 (file)
@@ -665,6 +665,22 @@ class User
                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
         *
index 61ac4fae00b11634117dcd17bfba73f8b76b1db3..62318bedbf2229c8cedb89a70ac84834213bfb2d 100644 (file)
@@ -39,6 +39,7 @@ use Friendica\Util\Network;
 use LightOpenID;
 use Friendica\Core\L10n;
 use Friendica\Core\Worker;
+use Friendica\Model\Contact;
 use Psr\Log\LoggerInterface;
 
 /**
@@ -358,8 +359,12 @@ class Authentication
                        $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) {
index 3eaa022c502152361e822eb59f2f8121fc00d8cc..27a3dfa11b2328f83c1cc60f6b86dfe98bafd6e0 100644 (file)
 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;
 
@@ -100,6 +103,14 @@ class OAuth
                        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;
        }
 
index 5bc6476145b352867f6cd43cb42f3993a2bff237..478ba89a96a118e77e51a05a8b65c5e9beca3701 100644 (file)
@@ -32,7 +32,7 @@ class UpdateAllSuggestions
 {
        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']);
                }
index 55c900916b8051c500871f2d4ff5818ac947fd05..2979ca80d01aa1a7c606bcf4f1545202dd26cdf0 100644 (file)
@@ -115,6 +115,7 @@ return [
                        "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"],