2023-03-31 22:32:36 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Site
|
|
|
|
module BuildStats
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
|
|
|
# Devuelve el tiempo promedio de publicación para este sitio
|
|
|
|
#
|
|
|
|
# @return [Integer]
|
|
|
|
def average_publication_time
|
|
|
|
build_stats.group(:action).average(:seconds).values.reduce(:+).round
|
|
|
|
end
|
|
|
|
|
|
|
|
# Devuelve el tiempo promedio de compilación para sitios similares
|
|
|
|
# a este.
|
|
|
|
#
|
|
|
|
# @return [Integer]
|
|
|
|
def average_publication_time_for_similar_sites
|
|
|
|
similar_deploys = Deploy.where(type: deploys.pluck(:type)).pluck(:id)
|
|
|
|
|
|
|
|
BuildStat.where(deploy_id: similar_deploys).group(:action).average(:seconds).values.reduce(:+).round
|
|
|
|
end
|
|
|
|
|
|
|
|
# Define si podemos calcular el tiempo promedio de publicación
|
|
|
|
# para este sitio
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
def average_publication_time_calculable?
|
2023-03-31 23:51:20 +00:00
|
|
|
build_stats.jekyll.where(status: true).count > 1
|
2023-03-31 22:32:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def similar_sites?
|
|
|
|
!design.no_theme?
|
|
|
|
end
|
|
|
|
|
|
|
|
# Detecta si el sitio todavía no ha sido publicado
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
def not_published_yet?
|
|
|
|
build_stats.jekyll.where(status: true).count.zero?
|
|
|
|
end
|
2023-04-20 21:22:00 +00:00
|
|
|
|
2023-04-21 15:10:03 +00:00
|
|
|
# Cambios posibles luego de la última publicación exitosa:
|
|
|
|
#
|
|
|
|
# * Artículos modificados
|
|
|
|
# * Configuración modificada
|
|
|
|
# * Métodos de publicación añadidos
|
2023-04-20 21:22:00 +00:00
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
def awaiting_publication?
|
2023-04-21 15:15:22 +00:00
|
|
|
waiting? && (post_pending? || deploy_pending? || configuration_pending?)
|
2023-04-21 15:10:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Se modificaron artículos después de publicar el sitio por última
|
|
|
|
# vez
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
2023-04-21 15:15:22 +00:00
|
|
|
def post_pending?
|
2023-04-21 15:10:03 +00:00
|
|
|
last_indexed_post_time > last_publication_time
|
|
|
|
end
|
|
|
|
|
|
|
|
# Se modificó el sitio después de publicarlo por última vez
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
2023-04-21 15:15:22 +00:00
|
|
|
def deploy_pending?
|
|
|
|
last_deploy_time > last_publication_time
|
|
|
|
end
|
|
|
|
|
|
|
|
# Se modificó la configuración del sitio
|
|
|
|
#
|
|
|
|
# @return [Boolean]
|
|
|
|
def configuration_pending?
|
|
|
|
last_configuration_time > last_publication_time
|
2023-04-21 15:10:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2023-04-21 15:15:22 +00:00
|
|
|
# Encuentra la fecha del último artículo modificado. Si no hay
|
|
|
|
# ninguno, devuelve la fecha de modificación del sitio.
|
2023-04-21 15:10:03 +00:00
|
|
|
#
|
|
|
|
# @return [Time]
|
|
|
|
def last_indexed_post_time
|
|
|
|
indexed_posts.order(updated_at: :desc).select(:updated_at).first&.updated_at || updated_at
|
|
|
|
end
|
|
|
|
|
2023-04-21 15:15:22 +00:00
|
|
|
# Encuentra la fecha de última modificación de los métodos de
|
|
|
|
# publicación.
|
|
|
|
#
|
|
|
|
# @return [Time]
|
|
|
|
def last_deploy_time
|
2023-04-21 16:47:02 +00:00
|
|
|
deploys.order(created_at: :desc).select(:created_at).first&.created_at || updated_at
|
2023-04-21 15:15:22 +00:00
|
|
|
end
|
|
|
|
|
2023-04-21 15:10:03 +00:00
|
|
|
# Encuentra la fecha de última publicación exitosa, si no hay
|
|
|
|
# ninguno, devuelve la fecha de modificación del sitio.
|
|
|
|
#
|
|
|
|
# @return [Time]
|
|
|
|
def last_publication_time
|
|
|
|
build_stats.jekyll.where(status: true).order(created_at: :desc).select(:created_at).first&.created_at || updated_at
|
2023-04-20 21:22:00 +00:00
|
|
|
end
|
2023-04-21 15:15:22 +00:00
|
|
|
|
|
|
|
# Fecha de última modificación de la configuración
|
|
|
|
#
|
|
|
|
# @return [Time]
|
|
|
|
def last_configuration_time
|
|
|
|
File.mtime(config.path)
|
|
|
|
end
|
2023-03-31 22:32:36 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|