summaryrefslogtreecommitdiff
path: root/app/presenters/event_presenter.rb
blob: 8f2388c2c3175e42b0b235f9c6694f667c97dfa3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# frozen_string_literal: true

class EventPresenter < Gitlab::View::Presenter::Delegated
  presents :event

  def initialize(subject, **attributes)
    super

    @visible_to_user_cache = ActiveSupport::Cache::MemoryStore.new
  end

  # Caching `visible_to_user?` method in the presenter beause it might be called multiple times.
  def visible_to_user?(user = nil)
    @visible_to_user_cache.fetch(user&.id) { super(user) }
  end

  # implement cache here
  def resource_parent_name
    resource_parent&.full_name || ''
  end

  def target_link_options
    case resource_parent
    when Group
      [event.group, event.target]
    when Project
      [event.project, event.target]
    else
      ''
    end
  end
end