Finally put tag_list_cache to rest (fixes philomena-dev/philomena#128)

This commit is contained in:
byte[] 2021-07-15 20:14:41 -04:00
parent 38c134668a
commit 66c758cb13
9 changed files with 25 additions and 13 deletions

View file

@ -54,6 +54,15 @@ defmodule Philomena.Images do
Repo.one!(Image |> where(id: ^id) |> preload(:tags)) Repo.one!(Image |> where(id: ^id) |> preload(:tags))
end end
@doc """
Gets the tag list for a single image.
"""
def tag_list(%Image{tags: tags}) do
tags
|> Tag.display_order()
|> Enum.map_join(", ", & &1.name)
end
@doc """ @doc """
Creates a image. Creates a image.

View file

@ -22,9 +22,7 @@ defmodule Philomena.Scrapers.Tumblr do
[post_id] = Regex.run(@url_regex, url, capture: :all_but_first) [post_id] = Regex.run(@url_regex, url, capture: :all_but_first)
api_url = api_url =
"https://api.tumblr.com/v2/blog/#{uri.host}/posts/photo?id=#{post_id}&api_key=#{ "https://api.tumblr.com/v2/blog/#{uri.host}/posts/photo?id=#{post_id}&api_key=#{tumblr_api_key()}"
tumblr_api_key()
}"
Philomena.Http.get(api_url) Philomena.Http.get(api_url)
|> json!() |> json!()

View file

@ -95,7 +95,7 @@ defmodule PhilomenaWeb.ImageController do
interactions: interactions, interactions: interactions,
watching: watching, watching: watching,
layout_class: "layout--wide", layout_class: "layout--wide",
title: "##{image.id} - #{image.tag_list_cache}" title: "##{image.id} - #{Images.tag_list(image)}"
] ]
if image.hidden_from_users do if image.hidden_from_users do

View file

@ -8,10 +8,10 @@
<%= for image <- @images do %> <%= for image <- @images do %>
<item> <item>
<title>#<%= image.id %> - <%= image.tag_list_cache %></title> <title>#<%= image.id %> - <%= tag_list(image) %></title>
<description> <description>
<![CDATA[ <![CDATA[
<% mouseovertext = "Size: #{image.image_width}x#{image.image_height} | Tagged: #{image.tag_list_cache}" %> <% mouseovertext = "Size: #{image.image_width}x#{image.image_height} | Tagged: #{tag_list(image)}" %>
<a href="<%= Routes.image_url(@conn, :show, image) %>"> <a href="<%= Routes.image_url(@conn, :show, image) %>">
<img src="<%= medium_url(image) %>" alt="<%= mouseovertext %>" title="<%= mouseovertext %>"/> <img src="<%= medium_url(image) %>" alt="<%= mouseovertext %>" title="<%= mouseovertext %>"/>
</a> </a>

View file

@ -5,9 +5,9 @@ meta name="format-detection" content="telephone=no"
= if opengraph?(@conn) do = if opengraph?(@conn) do
- image = @conn.assigns.image - image = @conn.assigns.image
- filtered = not image.thumbnails_generated - filtered = not image.thumbnails_generated
- description = "##{image.id} - #{image.tag_list_cache} - Derpibooru" - description = "##{image.id} - #{Philomena.Images.tag_list(image)} - Derpibooru"
meta name="keywords" content=image.tag_list_cache meta name="keywords" content=tag_list(image)
meta name="description" content=description meta name="description" content=description
meta property="og:title" content=description meta property="og:title" content=description
meta property="og:url" content=Routes.image_url(@conn, :show, image) meta property="og:url" content=Routes.image_url(@conn, :show, image)

View file

@ -11,7 +11,7 @@ defmodule PhilomenaWeb.Api.Json.OembedView do
%{ %{
version: "1.0", version: "1.0",
type: "photo", type: "photo",
title: "##{image.id} - #{image.tag_list_cache} - Derpibooru", title: "##{image.id} - #{tag_list(image)} - Derpibooru",
author_url: image.source_url || "", author_url: image.source_url || "",
author_name: artist_tags(image.tags), author_name: artist_tags(image.tags),
provider_name: "Derpibooru", provider_name: "Derpibooru",

View file

@ -43,6 +43,10 @@ defmodule PhilomenaWeb.AppView do
) )
end end
def tag_list(image) do
Philomena.Images.tag_list(image)
end
def distance_of_time_in_words(time_2, time_1) do def distance_of_time_in_words(time_2, time_1) do
seconds = abs(DateTime.diff(time_2, time_1, :second)) seconds = abs(DateTime.diff(time_2, time_1, :second))
minutes = div(seconds, 60) minutes = div(seconds, 60)

View file

@ -58,10 +58,10 @@ defmodule PhilomenaWeb.AvatarGeneratorView do
# 32-bit xorshift deterministic PRNG # 32-bit xorshift deterministic PRNG
defp xorshift32(state) do defp xorshift32(state) do
state = state &&& 0xFFFF_FFFF state = state &&& 0xFFFF_FFFF
state = bxor(state, (state <<< 13)) state = bxor(state, state <<< 13)
state = bxor(state, (state >>> 17)) state = bxor(state, state >>> 17)
bxor(state, (state <<< 5)) bxor(state, state <<< 5)
end end
# Generate pseudorandom, clamped RGB values with a specified # Generate pseudorandom, clamped RGB values with a specified

View file

@ -55,7 +55,8 @@ defmodule Philomena.MixProject do
{:nimble_parsec, "~> 1.1"}, {:nimble_parsec, "~> 1.1"},
{:canary, "~> 1.1"}, {:canary, "~> 1.1"},
{:scrivener_ecto, "~> 2.7"}, {:scrivener_ecto, "~> 2.7"},
{:pbkdf2, "~> 2.0", github: "code-time/erlang-pbkdf2", ref: "f8f0012a97f58ade9c70ac93260e4259e4ca4b8d"}, {:pbkdf2, "~> 2.0",
github: "code-time/erlang-pbkdf2", ref: "f8f0012a97f58ade9c70ac93260e4259e4ca4b8d"},
{:qrcode, "~> 0.1"}, {:qrcode, "~> 0.1"},
{:redix, "~> 0.10.0"}, {:redix, "~> 0.10.0"},
{:bamboo, "~> 1.6"}, {:bamboo, "~> 1.6"},