Class: Seo::VisitsSyncService
- Inherits:
-
BaseService
- Object
- BaseService
- Seo::VisitsSyncService
- Defined in:
- app/services/seo/visits_sync_service.rb
Overview
Applies rolling first-party page-view counts from the bounded daily
aggregate to SiteMap data points and the sortable 30-day cache column.
Aggregate refresh is deliberately owned by separate, one-day Sidekiq jobs.
Constant Summary collapse
- BATCH_SIZE =
500
Instance Attribute Summary
Attributes inherited from BaseService
Instance Method Summary collapse
-
#call ⇒ Hash
Page count plus a deferred flag when 90-day coverage is not ready yet.
-
#initialize(options = {}) ⇒ VisitsSyncService
constructor
A new instance of VisitsSyncService.
Methods inherited from BaseService
#log_debug, #log_error, #log_info, #log_warning, #logger, #process, #tagged_logger
Constructor Details
#initialize(options = {}) ⇒ VisitsSyncService
Returns a new instance of VisitsSyncService.
19 20 21 22 23 24 |
# File 'app/services/seo/visits_sync_service.rb', line 19 def initialize( = {}) super @site_map_ids = [:site_map_ids] @period_end = ([:period_end] || Date.current).to_date @stats = { pages_updated: 0, errors: [], deferred: false } end |
Instance Method Details
#call ⇒ Hash
Returns page count plus a deferred flag when 90-day coverage is not
ready yet.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'app/services/seo/visits_sync_service.rb', line 28 def call counts_query = Seo::VisitPageDailyCountsQuery.new(period_end: @period_end) unless counts_query.coverage_complete? @logger.warn("[VisitsSyncService] Deferred: daily aggregate is incomplete through #{@period_end}") return @stats.merge(deferred: true) end recorded_at = Time.current batch_id = SecureRandom.uuid @logger.info("[VisitsSyncService] Applying visit counts through #{@period_end}") site_maps_scope.in_batches(of: BATCH_SIZE) do |batch| apply_batch(batch.pluck(:id, :path), counts_query, recorded_at:, batch_id:) end @logger.info("[VisitsSyncService] Completed: #{@stats[:pages_updated]} pages updated") @stats end |