mirror of
https://git.nerdvpn.de/NerdVPN.de/invidious
synced 2026-02-14 22:51:42 +01:00
add support for redis socket
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
From 582ff8557eae31ab442d2d9b9801c27b7d1ccfb1 Mon Sep 17 00:00:00 2001
|
||||
From 3dbe502a6b7e6d0e69442b813f93b169acb5bbc1 Mon Sep 17 00:00:00 2001
|
||||
From: Emilien Devos <contact@emiliendevos.be>
|
||||
Date: Sat, 11 Feb 2023 19:56:50 +0100
|
||||
Subject: [PATCH 1/1] use redis for video cache
|
||||
@@ -6,11 +6,11 @@ Subject: [PATCH 1/1] use redis for video cache
|
||||
---
|
||||
shard.lock | 15 ++++++++++++---
|
||||
shard.yml | 2 ++
|
||||
src/invidious.cr | 2 ++
|
||||
src/invidious/config.cr | 1 +
|
||||
src/invidious.cr | 9 ++++++++-
|
||||
src/invidious/config.cr | 2 ++
|
||||
src/invidious/database/videos.cr | 16 +++++++++++++---
|
||||
src/invidious/videos.cr | 2 +-
|
||||
6 files changed, 31 insertions(+), 7 deletions(-)
|
||||
6 files changed, 38 insertions(+), 8 deletions(-)
|
||||
|
||||
diff --git a/shard.lock b/shard.lock
|
||||
index 235e4c25..8d61c101 100644
|
||||
@@ -69,7 +69,7 @@ index 7ee0bb2a..97cc35e9 100644
|
||||
development_dependencies:
|
||||
spectator:
|
||||
diff --git a/src/invidious.cr b/src/invidious.cr
|
||||
index d4f8e0fb..e473fce4 100644
|
||||
index d4f8e0fb..b52a9178 100644
|
||||
--- a/src/invidious.cr
|
||||
+++ b/src/invidious.cr
|
||||
@@ -31,6 +31,7 @@ require "xml"
|
||||
@@ -80,28 +80,36 @@ index d4f8e0fb..e473fce4 100644
|
||||
|
||||
require "./invidious/database/*"
|
||||
require "./invidious/database/migrations/*"
|
||||
@@ -60,6 +61,7 @@ CONFIG = Config.load
|
||||
@@ -59,7 +60,13 @@ alias IV = Invidious
|
||||
CONFIG = Config.load
|
||||
HMAC_KEY = CONFIG.hmac_key || Random::Secure.hex(32)
|
||||
|
||||
PG_DB = DB.open CONFIG.database_url
|
||||
+REDIS_DB = Redis::PooledClient.new(url: CONFIG.redis_url)
|
||||
-PG_DB = DB.open CONFIG.database_url
|
||||
+PG_DB = DB.open CONFIG.database_url
|
||||
+if CONFIG.redis_socket
|
||||
+ REDIS_DB = Redis::PooledClient.new(url: CONFIG.redis_socket)
|
||||
+else
|
||||
+ REDIS_DB = Redis::PooledClient.new(url: CONFIG.redis_url)
|
||||
+end
|
||||
+
|
||||
ARCHIVE_URL = URI.parse("https://archive.org")
|
||||
LOGIN_URL = URI.parse("https://accounts.google.com")
|
||||
PUBSUB_URL = URI.parse("https://pubsubhubbub.appspot.com")
|
||||
diff --git a/src/invidious/config.cr b/src/invidious/config.cr
|
||||
index 9fc58409..e411ac2e 100644
|
||||
index 9fc58409..524b2513 100644
|
||||
--- a/src/invidious/config.cr
|
||||
+++ b/src/invidious/config.cr
|
||||
@@ -74,6 +74,7 @@ class Config
|
||||
@@ -74,6 +74,8 @@ class Config
|
||||
# Database configuration using 12-Factor "Database URL" syntax
|
||||
@[YAML::Field(converter: Preferences::URIConverter)]
|
||||
property database_url : URI = URI.parse("")
|
||||
+ property redis_url : String
|
||||
+ property redis_url : String?
|
||||
+ property redis_socket : String?
|
||||
# Use polling to keep decryption function up to date
|
||||
property decrypt_polling : Bool = false
|
||||
# Used for crawling channels: threads should check all videos uploaded by a channel
|
||||
diff --git a/src/invidious/database/videos.cr b/src/invidious/database/videos.cr
|
||||
index 695f5b33..d2b57179 100644
|
||||
index 695f5b33..776ef5b1 100644
|
||||
--- a/src/invidious/database/videos.cr
|
||||
+++ b/src/invidious/database/videos.cr
|
||||
@@ -10,7 +10,8 @@ module Invidious::Database::Videos
|
||||
@@ -131,9 +139,9 @@ index 695f5b33..d2b57179 100644
|
||||
- return PG_DB.query_one?(request, id, as: Video)
|
||||
+ if ((info = REDIS_DB.get(id)) && (time = REDIS_DB.get(id + ":time")))
|
||||
+ return Video.new({
|
||||
+ id: id,
|
||||
+ info: JSON.parse(info).as_h,
|
||||
+ updated: Time.parse(time, "%Y-%m-%d %H:%M:%S %z", Time::Location::UTC)
|
||||
+ id: id,
|
||||
+ info: JSON.parse(info).as_h,
|
||||
+ updated: Time.parse(time, "%Y-%m-%d %H:%M:%S %z", Time::Location::UTC),
|
||||
+ })
|
||||
+ else
|
||||
+ return nil
|
||||
|
||||
Reference in New Issue
Block a user