Class: EventCollection
- Inherits:
-
Object
- Object
- EventCollection
- 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
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
Instance Method Summary collapse
- #all_project_events ⇒ Object
-
#initialize(projects, limit: 20, offset: 0, filter: nil, groups: nil, preserve_projects_order: false) ⇒ EventCollection
constructor
projects - An ActiveRecord::Relation object that returns the projects for which to retrieve events.
-
#to_a ⇒ Object
Returns an Array containing the events.
Constructor Details
#initialize(projects, limit: 20, offset: 0, filter: nil, groups: nil, preserve_projects_order: false) ⇒ EventCollection
projects - An ActiveRecord::Relation object that returns the projects for
which to retrieve events.
filter - An EventFilter instance to use for filtering events. preserve_projects_order - If true, retains the :order clause for projects.
21 22 23 24 25 26 27 28 |
# File 'app/models/event_collection.rb', line 21 def initialize(projects, limit: 20, offset: 0, filter: nil, groups: nil, preserve_projects_order: false) @projects = projects @limit = limit @offset = offset @filter = filter || EventFilter.new(EventFilter::ALL) @groups = groups @preserve_projects_order = preserve_projects_order end |
Instance Attribute Details
#filter ⇒ Object (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_events ⇒ Object
44 45 46 |
# File 'app/models/event_collection.rb', line 44 def all_project_events Event.from_union([project_events]).recent end |
#to_a ⇒ Object
Returns an Array containing the events.
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'app/models/event_collection.rb', line 31 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 |