Class: EventCollection

Inherits:
Object
  • Object
show all
Includes:
Gitlab::Utils::StrongMemoize
Defined in:
app/models/event_collection.rb

Overview

A collection of events to display in an event list.

An EventCollection is meant to be used for displaying events to a user (e.g. in a controller), it’s not suitable for building queries that are used for building other queries.

Constant Summary collapse

MAX_PAGE =

To prevent users from putting too much pressure on the database by cycling through thousands of events we put a limit on the number of pages.

10

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(projects, limit: 20, offset: 0, filter: nil, groups: nil) ⇒ EventCollection

projects - An ActiveRecord::Relation object that returns the projects for

which to retrieve events.

filter - An EventFilter instance to use for filtering events.



20
21
22
23
24
25
26
# File 'app/models/event_collection.rb', line 20

def initialize(projects, limit: 20, offset: 0, filter: nil, groups: nil)
  @projects = projects
  @limit = limit
  @offset = offset
  @filter = filter || EventFilter.new(EventFilter::ALL)
  @groups = groups
end

Instance Attribute Details

#filterObject (readonly)

Returns the value of attribute filter.



11
12
13
# File 'app/models/event_collection.rb', line 11

def filter
  @filter
end

Instance Method Details

#all_project_eventsObject



42
43
44
# File 'app/models/event_collection.rb', line 42

def all_project_events
  Event.from_union([project_events]).recent
end

#to_aObject

Returns an Array containing the events.



29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/event_collection.rb', line 29

def to_a
  return [] if current_page > MAX_PAGE

  relation = if groups
               project_and_group_events
             else
               project_events
             end

  relation = paginate_events(relation)
  relation.with_associations.to_a
end