Skip to content

Add user last activity info

James Lopez requested to merge feature/user-activity into master

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.


**Things to check:**

Projects::GitHttpController reads:

# 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...


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:

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; 
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

Merge request reports