Sha256: 8a6174ae0c97ee1a04ee2f29d466bac454b2b85bc9af2d0bbbbc54e846189090
Contents?: true
Size: 948 Bytes
Versions: 62
Compression:
Stored size: 948 Bytes
Contents
module Workarea module Metrics module ByWeek extend ActiveSupport::Concern include ApplicationDocument include Scoring included do store_in client: :metrics field :reporting_on, type: Time, default: -> { Time.current } index({ reporting_on: 1 }, { expire_after_seconds: 2.years.seconds.to_i }) scope :last_week, -> do where( :reporting_on.gte => Time.current.last_week, :reporting_on.lt => Time.current.last_week.end_of_week ) end end module ClassMethods def append!(scope) per_page = Workarea.config.insights_aggregation_per_page pages = scope.page(1).per(per_page).total_pages pages.times do |page| models = scope.page(page + 1).per(per_page).to_a collection.insert_many(models.map(&:as_document)) end end end end end end
Version data entries
62 entries across 62 versions & 1 rubygems