mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-26 13:16:21 +00:00
Merge branch 'blazer' into panel.sutty.nl
This commit is contained in:
commit
ef786d8af7
2 changed files with 43 additions and 11 deletions
|
@ -13,7 +13,7 @@
|
|||
class UriCollectionJob < PeriodicJob
|
||||
# Ignoramos imágenes porque suelen ser demasiadas y no aportan a las
|
||||
# estadísticas.
|
||||
IMAGES = %w[.png .jpg .jpeg .gif .webp].freeze
|
||||
IMAGES = %w[.png .jpg .jpeg .gif .webp .jfif].freeze
|
||||
STAT_NAME = 'uri_collection_job'
|
||||
|
||||
def perform(site_id:, once: true)
|
||||
|
@ -37,6 +37,7 @@ class UriCollectionJob < PeriodicJob
|
|||
# intervalo más amplio.
|
||||
Stat::INTERVALS.reduce do |previous, current|
|
||||
Rollup.where(name: 'host|uri', interval: previous)
|
||||
.where('time >= ?', beginning_of_interval)
|
||||
.where_dimensions(host: hostname, uri: uri)
|
||||
.group("dimensions->'host'", "dimensions->'uri'")
|
||||
.rollup('host|uri', interval: current, update: true) do |rollup|
|
||||
|
@ -91,18 +92,46 @@ class UriCollectionJob < PeriodicJob
|
|||
#
|
||||
# @return [Array]
|
||||
def uris
|
||||
@uris ||= Dir.chdir destination do
|
||||
(Dir.glob('**/*.html') + Dir.glob('public/**/*').reject do |p|
|
||||
File.directory? p
|
||||
end.reject do |p|
|
||||
p = p.downcase
|
||||
@uris ||=
|
||||
locales.map do |locale|
|
||||
uri = "/#{locale}/".squeeze('/')
|
||||
dir = File.join(destination, locale)
|
||||
|
||||
IMAGES.any? do |i|
|
||||
p.end_with? i
|
||||
files(dir).map do |f|
|
||||
uri + f
|
||||
end
|
||||
end).map do |uri|
|
||||
"/#{uri}"
|
||||
end.flatten(2)
|
||||
end
|
||||
|
||||
# @return [Array]
|
||||
def locales
|
||||
@locales ||= ['', site.locales.map(&:to_s)].flatten(1)
|
||||
end
|
||||
|
||||
# @param :dir [String]
|
||||
# @return [Array]
|
||||
def files(dir)
|
||||
Dir.chdir(dir) do
|
||||
pages = Dir.glob('**/*.html')
|
||||
files = Dir.glob('public/**/*')
|
||||
files = remove_directories files
|
||||
files = remove_images files
|
||||
|
||||
[pages, files].flatten(1)
|
||||
end
|
||||
end
|
||||
|
||||
# @param :files [Array]
|
||||
# @return [Array]
|
||||
def remove_directories(files)
|
||||
files.reject do |f|
|
||||
File.directory? f
|
||||
end
|
||||
end
|
||||
|
||||
def remove_images(files)
|
||||
files.reject do |f|
|
||||
IMAGES.include? File.extname(f).downcase
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
3
app/models/site_stat.rb
Normal file
3
app/models/site_stat.rb
Normal file
|
@ -0,0 +1,3 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
SiteStat = Struct.new(:site)
|
Loading…
Reference in a new issue