mirror of
https://gitea.invidious.io/iv-org/invidious-copy-2023-06-08.git
synced 2024-08-15 00:53:38 +00:00
Move DB queries related to 'annotations' in a separate module
This commit is contained in:
parent
85cf27119c
commit
914cfbd953
3 changed files with 26 additions and 2 deletions
24
src/invidious/database/annotations.cr
Normal file
24
src/invidious/database/annotations.cr
Normal file
|
@ -0,0 +1,24 @@
|
|||
require "./base.cr"
|
||||
|
||||
module Invidious::Database::Annotations
|
||||
extend self
|
||||
|
||||
def insert(id : String, annotations : String)
|
||||
request = <<-SQL
|
||||
INSERT INTO annotations
|
||||
VALUES ($1, $2)
|
||||
ON CONFLICT DO NOTHING
|
||||
SQL
|
||||
|
||||
PG_DB.exec(request, id, annotations)
|
||||
end
|
||||
|
||||
def select(id : String) : Annotation?
|
||||
request = <<-SQL
|
||||
SELECT * FROM annotations
|
||||
WHERE id = $1
|
||||
SQL
|
||||
|
||||
return PG_DB.query_one?(request, id, as: Annotation)
|
||||
end
|
||||
end
|
|
@ -183,7 +183,7 @@ def cache_annotation(db, id, annotations)
|
|||
end
|
||||
end
|
||||
|
||||
db.exec("INSERT INTO annotations VALUES ($1, $2) ON CONFLICT DO NOTHING", id, annotations) if has_legacy_annotations
|
||||
Invidious::Database::Annotations.insert(id, annotations) if has_legacy_annotations
|
||||
end
|
||||
|
||||
def create_notification_stream(env, topics, connection_channel)
|
||||
|
|
|
@ -239,7 +239,7 @@ module Invidious::Routes::API::V1::Videos
|
|||
|
||||
case source
|
||||
when "archive"
|
||||
if CONFIG.cache_annotations && (cached_annotation = PG_DB.query_one?("SELECT * FROM annotations WHERE id = $1", id, as: Annotation))
|
||||
if CONFIG.cache_annotations && (cached_annotation = Invidious::Database::Annotations.select(id))
|
||||
annotations = cached_annotation.annotations
|
||||
else
|
||||
index = CHARS_SAFE.index(id[0]).not_nil!.to_s.rjust(2, '0')
|
||||
|
|
Loading…
Reference in a new issue