diff options
| author | Samantaz Fox <coding@samantaz.fr> | 2021-12-06 17:24:49 +0100 |
|---|---|---|
| committer | Samantaz Fox <coding@samantaz.fr> | 2022-01-04 17:15:43 +0100 |
| commit | 914cfbd953d5a2c3c6f8ae98f350b60bfb38b9a2 (patch) | |
| tree | 1e21fb201798df03c557c268ed7fc1d6e6cf1820 | |
| parent | 85cf27119cb230259550bfb795dffcb724ebebf3 (diff) | |
| download | invidious-914cfbd953d5a2c3c6f8ae98f350b60bfb38b9a2.tar.gz invidious-914cfbd953d5a2c3c6f8ae98f350b60bfb38b9a2.tar.bz2 invidious-914cfbd953d5a2c3c6f8ae98f350b60bfb38b9a2.zip | |
Move DB queries related to 'annotations' in a separate module
| -rw-r--r-- | src/invidious/database/annotations.cr | 24 | ||||
| -rw-r--r-- | src/invidious/helpers/helpers.cr | 2 | ||||
| -rw-r--r-- | src/invidious/routes/api/v1/videos.cr | 2 |
3 files changed, 26 insertions, 2 deletions
diff --git a/src/invidious/database/annotations.cr b/src/invidious/database/annotations.cr new file mode 100644 index 00000000..03749473 --- /dev/null +++ b/src/invidious/database/annotations.cr @@ -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 diff --git a/src/invidious/helpers/helpers.cr b/src/invidious/helpers/helpers.cr index 014c04a8..c5f6c6c5 100644 --- a/src/invidious/helpers/helpers.cr +++ b/src/invidious/helpers/helpers.cr @@ -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) diff --git a/src/invidious/routes/api/v1/videos.cr b/src/invidious/routes/api/v1/videos.cr index 4c7179ce..f982329c 100644 --- a/src/invidious/routes/api/v1/videos.cr +++ b/src/invidious/routes/api/v1/videos.cr @@ -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') |
