From a675c64c2df27f2269ffe4c229d2ec6e95ba6567 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Tue, 21 May 2019 09:00:35 -0500 Subject: [PATCH] Refactor DBConfig --- src/invidious.cr | 10 +++++----- src/invidious/helpers/helpers.cr | 22 +++++++++++++--------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index a6b23504..b82567ef 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -33,11 +33,11 @@ HMAC_KEY = CONFIG.hmac_key || Random::Secure.hex(32) PG_URL = URI.new( scheme: "postgres", - user: CONFIG.db[:user], - password: CONFIG.db[:password], - host: CONFIG.db[:host], - port: CONFIG.db[:port], - path: CONFIG.db[:dbname], + user: CONFIG.db.user, + password: CONFIG.db.password, + host: CONFIG.db.host, + port: CONFIG.db.port, + path: CONFIG.db.dbname, ) PG_DB = DB.open PG_URL diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index 5ba9729b..791d6782 100644 --- a/src/invidious/helpers/helpers.cr +++ b/src/invidious/helpers/helpers.cr @@ -97,15 +97,9 @@ struct Config end YAML.mapping({ - channel_threads: Int32, # Number of threads to use for crawling videos from channels (for updating subscriptions) - feed_threads: Int32, # Number of threads to use for updating feeds - db: NamedTuple( # Database configuration -user: String, - password: String, - host: String, - port: Int32, - dbname: String, - ), + channel_threads: Int32, # Number of threads to use for crawling videos from channels (for updating subscriptions) + feed_threads: Int32, # Number of threads to use for updating feeds + db: DBConfig, # Database configuration full_refresh: Bool, # Used for crawling channels: threads should check all videos uploaded by a channel https_only: Bool?, # Used to tell Invidious it is behind a proxy, so links to resources should be https:// hmac_key: String?, # HMAC signing key for CSRF tokens and verifying pubsub subscriptions @@ -132,6 +126,16 @@ user: String, }) end +struct DBConfig + yaml_mapping({ + user: String, + password: String, + host: String, + port: Int32, + dbname: String, + }) +end + def rank_videos(db, n) top = [] of {Float64, String}