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 Method Summary collapse

Methods included from Gitlab::Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

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.


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

def initialize(projects, limit: 20, offset: 0, filter: nil, groups: nil)
  @projects = projects
  @limit = limit
  @offset = offset
  @filter = filter
  @groups = groups
end

Instance Method Details

#all_project_eventsObject


40
41
42
# File 'app/models/event_collection.rb', line 40

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

#to_aObject

Returns an Array containing the events.


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

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