diff options
author | James Lopez <james@jameslopez.es> | 2016-11-25 17:10:25 +0100 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-04-14 15:20:55 +0200 |
commit | 3cb84e06b7a118fb46b4e1e0d4885026c9d4a4d1 (patch) | |
tree | ef622687724fd429f6f7fb02a19a022550bf8608 /app | |
parent | 2951a8543ef97ceb1bcaca5f5140d822729c950b (diff) | |
download | gitlab-ce-3cb84e06b7a118fb46b4e1e0d4885026c9d4a4d1.tar.gz |
Remove user activities table and use redis instead of PG for recording activities
Refactored specs and added a post deployment migration to remove the activity users table.
Diffstat (limited to 'app')
-rw-r--r-- | app/models/user.rb | 10 | ||||
-rw-r--r-- | app/models/user_activity.rb | 19 | ||||
-rw-r--r-- | app/services/users/activity_service.rb | 6 |
3 files changed, 9 insertions, 26 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 1dde5c89699..83e17bcb04e 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -101,7 +101,6 @@ class User < ActiveRecord::Base has_many :assigned_issues, dependent: :nullify, foreign_key: :assignee_id, class_name: "Issue" has_many :assigned_merge_requests, dependent: :nullify, foreign_key: :assignee_id, class_name: "MergeRequest" - has_one :user_activity, dependent: :destroy # Issues that a user owns are expected to be moved to the "ghost" user before # the user is destroyed. If the user owns any issues during deletion, this @@ -159,7 +158,6 @@ class User < ActiveRecord::Base alias_attribute :private_token, :authentication_token delegate :path, to: :namespace, allow_nil: true, prefix: true - delegate :last_activity_at, to: :user_activity, allow_nil: true state_machine :state, initial: :active do event :block do @@ -951,6 +949,14 @@ class User < ActiveRecord::Base end end + def record_activity + Gitlab::Redis.with do |redis| + redis.zadd('user/activities', Time.now.to_i, self.username) + end + end + + private + def access_level=(new_level) new_level = new_level.to_s return unless %w(admin regular).include?(new_level) diff --git a/app/models/user_activity.rb b/app/models/user_activity.rb deleted file mode 100644 index c5fdbff0feb..00000000000 --- a/app/models/user_activity.rb +++ /dev/null @@ -1,19 +0,0 @@ -class UserActivity < ActiveRecord::Base - belongs_to :user, inverse_of: :user_activity - - validates :user, uniqueness: true, presence: true - validates :last_activity_at, presence: true - - # Updated version of http://apidock.com/rails/ActiveRecord/Timestamp/touch - # That accepts a new record. - def touch - current_time = current_time_from_proper_timezone - - if persisted? - update_column(:last_activity_at, current_time) - else - self.last_activity_at = current_time - save!(validate: false) - end - end -end diff --git a/app/services/users/activity_service.rb b/app/services/users/activity_service.rb index b81f947cd01..483821b7f01 100644 --- a/app/services/users/activity_service.rb +++ b/app/services/users/activity_service.rb @@ -14,13 +14,9 @@ module Users private def record_activity - user_activity.touch + @author.record_activity Rails.logger.debug("Recorded activity: #{@activity} for User ID: #{@author.id} (username: #{@author.username}") end - - def user_activity - UserActivity.find_or_initialize_by(user: @author) - end end end |