mirror of
https://github.com/iv-org/invidious.git
synced 2025-08-16 17:48:29 +00:00
always show all
This commit is contained in:
parent
39caca33d8
commit
435804edd1
@ -142,7 +142,7 @@ if CONFIG.decrypt_polling
|
|||||||
end
|
end
|
||||||
|
|
||||||
if CONFIG.statistics_enabled
|
if CONFIG.statistics_enabled
|
||||||
Invidious::Jobs.register Invidious::Jobs::StatisticsRefreshJob.new(PG_DB, SOFTWARE)
|
Invidious::Jobs.register Invidious::Jobs::StatisticsRefreshJob.new(PG_DB)
|
||||||
end
|
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)
|
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)
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
class Invidious::Jobs::StatisticsRefreshJob < Invidious::Jobs::BaseJob
|
class Invidious::Jobs::StatisticsRefreshJob < Invidious::Jobs::BaseJob
|
||||||
STATISTICS = {
|
STATISTICS = {
|
||||||
"version" => "2.0",
|
"version" => "3.0",
|
||||||
"software" => {
|
"software" => SOFTWARE,
|
||||||
"name" => "invidious",
|
"statisticsEnabled" => true,
|
||||||
"version" => "",
|
|
||||||
"branch" => "",
|
|
||||||
},
|
|
||||||
"openRegistrations" => true,
|
"openRegistrations" => true,
|
||||||
"usage" => {
|
"usage" => {
|
||||||
"users" => {
|
"users" => {
|
||||||
@ -22,12 +19,10 @@ class Invidious::Jobs::StatisticsRefreshJob < Invidious::Jobs::BaseJob
|
|||||||
|
|
||||||
private getter db : DB::Database
|
private getter db : DB::Database
|
||||||
|
|
||||||
def initialize(@db, @software_config : Hash(String, String))
|
def initialize(@db)
|
||||||
end
|
end
|
||||||
|
|
||||||
def begin
|
def begin
|
||||||
load_initial_stats
|
|
||||||
|
|
||||||
loop do
|
loop do
|
||||||
refresh_stats
|
refresh_stats
|
||||||
sleep 1.minute
|
sleep 1.minute
|
||||||
@ -35,17 +30,8 @@ class Invidious::Jobs::StatisticsRefreshJob < Invidious::Jobs::BaseJob
|
|||||||
end
|
end
|
||||||
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
|
private def refresh_stats
|
||||||
|
STATISTICS["openRegistrations"] = CONFIG.registration_enabled
|
||||||
users = STATISTICS.dig("usage", "users").as(Hash(String, Int64))
|
users = STATISTICS.dig("usage", "users").as(Hash(String, Int64))
|
||||||
users["total"] = db.query_one("SELECT count(*) FROM users", as: 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)
|
users["activeHalfyear"] = db.query_one("SELECT count(*) FROM users WHERE CURRENT_TIMESTAMP - updated < '6 months'", as: Int64)
|
||||||
|
@ -5,7 +5,23 @@ module Invidious::Routes::API::V1::Misc
|
|||||||
env.response.content_type = "application/json"
|
env.response.content_type = "application/json"
|
||||||
|
|
||||||
if !CONFIG.statistics_enabled
|
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
|
end
|
||||||
|
|
||||||
Invidious::Jobs::StatisticsRefreshJob::STATISTICS.to_json
|
Invidious::Jobs::StatisticsRefreshJob::STATISTICS.to_json
|
||||||
|
Loading…
Reference in New Issue
Block a user