recolección de estadísticas con mejor performance
This commit is contained in:
parent
9cf7c62861
commit
8d38d0d2ae
1 changed files with 26 additions and 16 deletions
|
@ -21,14 +21,20 @@ class StatCollectionJob < ApplicationJob
|
||||||
COLUMNS = %i[uri].freeze
|
COLUMNS = %i[uri].freeze
|
||||||
|
|
||||||
def perform(once: false)
|
def perform(once: false)
|
||||||
Stat::INTERVALS.each do |interval|
|
Site.find_each do |site|
|
||||||
options = { interval: interval }
|
hostnames = [site.hostname, site.alternative_hostnames].flatten
|
||||||
|
|
||||||
|
# Usamos el primero porque luego podemos hacer un rollup recursivo
|
||||||
|
options = { interval: Stat::INTERVALS.first }
|
||||||
|
|
||||||
# Visitas por hostname
|
# Visitas por hostname
|
||||||
AccessLog.completed_requests.non_robots.pages.group(:host).rollup('host', **options)
|
hostnames.each do |hostname|
|
||||||
|
AccessLog.where(host: hostname).completed_requests.non_robots.pages.group(:host).rollup('host', **options)
|
||||||
|
|
||||||
combined_columns(**options)
|
combined_columns(hostname, **options)
|
||||||
stats_by_site(**options)
|
end
|
||||||
|
|
||||||
|
stats_by_site(site, **options)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Registrar que se hicieron todas las recolecciones
|
# Registrar que se hicieron todas las recolecciones
|
||||||
|
@ -40,9 +46,15 @@ class StatCollectionJob < ApplicationJob
|
||||||
private
|
private
|
||||||
|
|
||||||
# Combinación de columnas
|
# Combinación de columnas
|
||||||
def combined_columns(**options)
|
def combined_columns(hostname, **options)
|
||||||
|
where = { host: hostname }
|
||||||
|
|
||||||
COLUMNS.each do |column|
|
COLUMNS.each do |column|
|
||||||
AccessLog.completed_requests.non_robots.group(:host, column).rollup("host|#{column}", **options)
|
AccessLog.where(host: hostname).pluck(Arel.sql("distinct #{column}")).each do |value|
|
||||||
|
where[column] = value
|
||||||
|
|
||||||
|
AccessLog.where(**where).completed_requests.non_robots.group(:host, column).rollup("host|#{column}", **options)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -50,8 +62,7 @@ class StatCollectionJob < ApplicationJob
|
||||||
#
|
#
|
||||||
# XXX: En realidad se agrupan por el deploy_id, que siempre será el
|
# XXX: En realidad se agrupan por el deploy_id, que siempre será el
|
||||||
# del DeployLocal.
|
# del DeployLocal.
|
||||||
def stats_by_site(**options)
|
def stats_by_site(site, **options)
|
||||||
Site.find_each do |site|
|
|
||||||
site.build_stats.jekyll.group(:deploy_id).rollup('builds', **options)
|
site.build_stats.jekyll.group(:deploy_id).rollup('builds', **options)
|
||||||
|
|
||||||
site.build_stats.jekyll.group(:deploy_id).rollup('space_used', **options) do |rollup|
|
site.build_stats.jekyll.group(:deploy_id).rollup('space_used', **options) do |rollup|
|
||||||
|
@ -63,4 +74,3 @@ class StatCollectionJob < ApplicationJob
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
Loading…
Reference in a new issue