Class: Mihari::Alert
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Mihari::Alert
- Defined in:
- lib/mihari/models/alert.rb
Class Method Summary collapse
-
.count(filter) ⇒ Integer
Count alerts.
-
.search(filter) ⇒ Array<Alert>
Search alerts.
Class Method Details
.count(filter) ⇒ Integer
Count alerts
41 42 43 44 |
# File 'lib/mihari/models/alert.rb', line 41 def count(filter) relation = build_relation(filter) relation.distinct("alerts.id").count end |
.search(filter) ⇒ Array<Alert>
Search alerts
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/mihari/models/alert.rb', line 19 def search(filter) limit = filter.limit.to_i raise ArgumentError, "limit should be bigger than zero" unless limit.positive? page = filter.page.to_i raise ArgumentError, "page should be bigger than zero" unless page.positive? offset = (page - 1) * limit relation = build_relation(filter.without_pagination) alert_ids = relation.limit(limit).offset(offset).order(id: :desc).pluck(:id).uniq eager_load(:artifacts, :tags).where(id: [alert_ids]).order(id: :desc) end |