debian-mirror-gitlab/app/models/concerns/board_recent_visit.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
674 B
Ruby
Raw Normal View History

2021-06-08 01:23:25 +05:30
# frozen_string_literal: true
module BoardRecentVisit
extend ActiveSupport::Concern
class_methods do
def visited!(user, board)
find_or_create_by(
"user" => user,
board_parent_relation => board.resource_parent,
board_relation => board
2023-03-17 16:20:25 +05:30
).tap(&:touch)
2021-06-08 01:23:25 +05:30
rescue ActiveRecord::RecordNotUnique
retry
end
def latest(user, parent, count: nil)
visits = by_user_parent(user, parent).order(updated_at: :desc)
visits = visits.preload(board_relation)
visits.first(count)
end
def board_relation
:board
end
def board_parent_relation
raise NotImplementedError
end
end
end