always show all

This commit is contained in:
706f6f7079646f6f646f6f 2021-10-08 19:57:58 +02:00
parent 39caca33d8
commit 435804edd1
3 changed files with 23 additions and 21 deletions

View File

@ -142,7 +142,7 @@ if CONFIG.decrypt_polling
end
if CONFIG.statistics_enabled
Invidious::Jobs.register Invidious::Jobs::StatisticsRefreshJob.new(PG_DB, SOFTWARE)
Invidious::Jobs.register Invidious::Jobs::StatisticsRefreshJob.new(PG_DB)
end
if (CONFIG.use_pubsub_feeds.is_a?(Bool) && CONFIG.use_pubsub_feeds.as(Bool)) || (CONFIG.use_pubsub_feeds.is_a?(Int32) && CONFIG.use_pubsub_feeds.as(Int32) > 0)

View File

@ -1,11 +1,8 @@
class Invidious::Jobs::StatisticsRefreshJob < Invidious::Jobs::BaseJob
STATISTICS = {
"version" => "2.0",
"software" => {
"name" => "invidious",
"version" => "",
"branch" => "",
},
"version" => "3.0",
"software" => SOFTWARE,
"statisticsEnabled" => true,
"openRegistrations" => true,
"usage" => {
"users" => {
@ -22,12 +19,10 @@ class Invidious::Jobs::StatisticsRefreshJob < Invidious::Jobs::BaseJob
private getter db : DB::Database
def initialize(@db, @software_config : Hash(String, String))
def initialize(@db)
end
def begin
load_initial_stats
loop do
refresh_stats
sleep 1.minute
@ -35,17 +30,8 @@ class Invidious::Jobs::StatisticsRefreshJob < Invidious::Jobs::BaseJob
end
end
# should only be called once at the very beginning
private def load_initial_stats
STATISTICS["software"] = {
"name" => @software_config["name"],
"version" => @software_config["version"],
"branch" => @software_config["branch"],
}
STATISTICS["openRegistrations"] = CONFIG.registration_enabled
end
private def refresh_stats
STATISTICS["openRegistrations"] = CONFIG.registration_enabled
users = STATISTICS.dig("usage", "users").as(Hash(String, Int64))
users["total"] = db.query_one("SELECT count(*) FROM users", as: Int64)
users["activeHalfyear"] = db.query_one("SELECT count(*) FROM users WHERE CURRENT_TIMESTAMP - updated < '6 months'", as: Int64)

View File

@ -5,7 +5,23 @@ module Invidious::Routes::API::V1::Misc
env.response.content_type = "application/json"
if !CONFIG.statistics_enabled
return error_json(400, "Statistics are not enabled.", {"software" => SOFTWARE})
return {
"version" => "3.0",
"software" => SOFTWARE,
"statisticsEnabled" => false,
"openRegistrations" => nil,
"usage" => {
"users" => {
"total" => nil,
"activeHalfyear" => nil,
"activeMonth" => nil,
},
},
"metadata" => {
"updatedAt" => nil,
"lastChannelRefreshedAt" => nil,
},
}.to_json
end
Invidious::Jobs::StatisticsRefreshJob::STATISTICS.to_json