• Rémy Coutable's avatar
    Merge branch 'feature/user-activity' into 'master' · 8c0c2f3e
    Rémy Coutable authored
    Add user last activity info
    
    Adds `last_activity_at` info to users to track any activity from the user including any Git operations or logging in into the UI.
    
    This adds a table with a 1-1 relationship with users, that gets updated every time the user logs in or runs any Git operation.
    
    <br />
    **Things to check:**
    
    ` Projects::GitHttpController` reads:
    
    ```ruby
    # This file should be identical in GitLab Community Edition and Enterprise Edition
    ```
    
    with no explanation. With this change, they will diverge as I added a `log_user_activity` method there. Not sure if this is a problem...
    
    <br />
    
    This MR allow us to query the DB for user activity, as requested by https://gitlab.com/gitlab-org/gitlab-ee/issues/1022
    
    ### mySQL examples - active users last month:
    
    ```sql
    SELECT u.username,
           a.last_activity_at
    FROM   users u
           INNER JOIN user_activities a
                   ON u.id = a.user_id
    WHERE  last_activity_at > (SELECT Now() - INTERVAL 1 month) -- INTERVAL '1 MONTH' in postgreSQL
    ORDER  BY last_activity_at; 
    ```
    
    ```sql
    SELECT Count(*)
    FROM   user_activities
    WHERE  last_activity_at > (SELECT Now() - INTERVAL 1 month); -- INTERVAL '1 MONTH' in postgreSQL
    ```
    
    Fixes https://gitlab.com/gitlab-org/gitlab-ee/issues/1022
    
    See merge request !781
    8c0c2f3e
schema.rb 57.2 KB