summaryrefslogtreecommitdiff
path: root/app/models/board_group_recent_visit.rb
diff options
context:
space:
mode:
authorHeinrich Lee Yu <heinrich@gitlab.com>2019-02-27 21:08:48 +0800
committerHeinrich Lee Yu <heinrich@gitlab.com>2019-03-01 19:47:52 +0800
commitc5b3b71e89996ba4e6fb977e3cbb3eebfbbfed4e (patch)
treef00ba49189df8a72f647c33c4670534f70c7cc64 /app/models/board_group_recent_visit.rb
parent31353188f84bd3e57318b4b1aa2da93a9d9605d1 (diff)
downloadgitlab-ce-c5b3b71e89996ba4e6fb977e3cbb3eebfbbfed4e.tar.gz
CE-port for 7714-view-recent-boards
Adds additional count param to Boards::Visits::LatestService
Diffstat (limited to 'app/models/board_group_recent_visit.rb')
-rw-r--r--app/models/board_group_recent_visit.rb9
1 files changed, 6 insertions, 3 deletions
diff --git a/app/models/board_group_recent_visit.rb b/app/models/board_group_recent_visit.rb
index 92abbb67222..f5b75270595 100644
--- a/app/models/board_group_recent_visit.rb
+++ b/app/models/board_group_recent_visit.rb
@@ -10,7 +10,7 @@ class BoardGroupRecentVisit < ActiveRecord::Base
validates :group, presence: true
validates :board, presence: true
- scope :by_user_group, -> (user, group) { where(user: user, group: group).order(:updated_at) }
+ scope :by_user_group, -> (user, group) { where(user: user, group: group) }
def self.visited!(user, board)
visit = find_or_create_by(user: user, group: board.group, board: board)
@@ -19,7 +19,10 @@ class BoardGroupRecentVisit < ActiveRecord::Base
retry
end
- def self.latest(user, group)
- by_user_group(user, group).last
+ def self.latest(user, group, count: nil)
+ visits = by_user_group(user, group).order(updated_at: :desc)
+ visits = visits.preload(:board) if count && count > 1
+
+ visits.first(count)
end
end