Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
liamwhite committed Aug 5, 2024
2 parents 48d672d + 8567a90 commit 87e8b82
Show file tree
Hide file tree
Showing 31 changed files with 24 additions and 214 deletions.
4 changes: 2 additions & 2 deletions index/posts.mk
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ metadata: post_search_json
'body', p.body,
'subject', t.title,
'ip', p.ip,
'user_agent', p.user_agent,
'referrer', p.referrer,
'user_agent', '',
'referrer', '',
'fingerprint', p.fingerprint,
'topic_position', p.topic_position,
'forum', f.short_name,
Expand Down
13 changes: 0 additions & 13 deletions lib/philomena/artist_links/artist_link.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ defmodule Philomena.ArtistLinks.ArtistLink do

field :aasm_state, :string, default: "unverified"
field :uri, :string
field :hostname, :string
field :path, :string
field :verification_code, :string
field :public, :boolean, default: true
field :next_check_at, :utc_datetime
Expand All @@ -35,15 +33,13 @@ defmodule Philomena.ArtistLinks.ArtistLink do
|> cast(attrs, [:uri, :public])
|> put_change(:tag_id, nil)
|> validate_required([:user, :uri, :public])
|> parse_uri()
end

def edit_changeset(artist_link, attrs, tag) do
artist_link
|> cast(attrs, [:uri, :public])
|> put_change(:tag_id, tag.id)
|> validate_required([:user, :uri, :public])
|> parse_uri()
end

def creation_changeset(artist_link, attrs, user, tag) do
Expand All @@ -55,7 +51,6 @@ defmodule Philomena.ArtistLinks.ArtistLink do
|> validate_required([:tag], message: "must exist")
|> validate_format(:uri, ~r|\Ahttps?://|)
|> validate_category()
|> parse_uri()
|> put_verification_code()
|> put_next_check_at()
|> unique_constraint([:uri, :tag_id, :user_id],
Expand Down Expand Up @@ -95,14 +90,6 @@ defmodule Philomena.ArtistLinks.ArtistLink do
|> put_change(:aasm_state, "contacted")
end

defp parse_uri(changeset) do
string_uri = get_field(changeset, :uri) |> to_string()
uri = URI.parse(string_uri)

changeset
|> change(hostname: uri.host, path: uri.path)
end

defp put_verification_code(changeset) do
code = :crypto.strong_rand_bytes(5) |> Base.encode16()
change(changeset, verification_code: "DERPI-LINKVALIDATION-#{code}")
Expand Down
11 changes: 0 additions & 11 deletions lib/philomena/channels/channel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,13 @@ defmodule Philomena.Channels.Channel do

field :short_name, :string
field :title, :string, default: ""
field :tags, :string
field :viewers, :integer, default: 0
field :nsfw, :boolean, default: false
field :is_live, :boolean, default: false
field :last_fetched_at, :utc_datetime
field :next_check_at, :utc_datetime
field :last_live_at, :utc_datetime

field :viewer_minutes_today, :integer, default: 0
field :viewer_minutes_thisweek, :integer, default: 0
field :viewer_minutes_thismonth, :integer, default: 0
field :total_viewer_minutes, :integer, default: 0

field :banner_image, :string
field :channel_image, :string
field :remote_stream_id, :integer
field :thumbnail_url, :string, default: ""

timestamps(inserted_at: :created_at, type: :utc_datetime)
end

Expand Down
7 changes: 0 additions & 7 deletions lib/philomena/comments/comment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@ defmodule Philomena.Comments.Comment do
field :body, :string
field :ip, EctoNetwork.INET
field :fingerprint, :string
field :user_agent, :string, default: ""
field :referrer, :string, default: ""
field :anonymous, :boolean, default: false
field :hidden_from_users, :boolean, default: false
field :edit_reason, :string
field :edited_at, :utc_datetime
field :deletion_reason, :string, default: ""
field :destroyed_content, :boolean, default: false
field :name_at_post_time, :string
field :approved, :boolean

timestamps(inserted_at: :created_at, type: :utc_datetime)
Expand All @@ -35,7 +32,6 @@ defmodule Philomena.Comments.Comment do
|> validate_required([:body])
|> validate_length(:body, min: 1, max: 20_000, count: :bytes)
|> change(attribution)
|> put_name_at_post_time(attribution[:user])
|> Approval.maybe_put_approval(attribution[:user])
|> Approval.maybe_strip_images(attribution[:user])
end
Expand Down Expand Up @@ -74,7 +70,4 @@ defmodule Philomena.Comments.Comment do
change(comment)
|> put_change(:approved, true)
end

defp put_name_at_post_time(changeset, nil), do: changeset
defp put_name_at_post_time(changeset, user), do: change(changeset, name_at_post_time: user.name)
end
9 changes: 0 additions & 9 deletions lib/philomena/images.ex
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ defmodule Philomena.Images do

Multi.new()
|> Multi.insert(:image, image)
|> Multi.run(:name_caches, fn repo, %{image: image} ->
image
|> Image.cache_changeset()
|> repo.update()
end)
|> Multi.run(:added_tag_count, fn repo, %{image: image} ->
tag_ids = image.added_tags |> Enum.map(& &1.id)
tags = Tag |> where([t], t.id in ^tag_ids)
Expand Down Expand Up @@ -386,8 +381,6 @@ defmodule Philomena.Images do
updated_at: now,
ip: attribution[:ip],
fingerprint: attribution[:fingerprint],
user_agent: attribution[:user_agent],
referrer: attribution[:referrer],
added: added
}
end
Expand Down Expand Up @@ -523,8 +516,6 @@ defmodule Philomena.Images do
tag_name_cache: tag.name,
ip: attribution[:ip],
fingerprint: attribution[:fingerprint],
user_agent: attribution[:user_agent],
referrer: attribution[:referrer],
added: added
}
end
Expand Down
57 changes: 0 additions & 57 deletions lib/philomena/images/image.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ defmodule Philomena.Images.Image do
use Ecto.Schema

import Ecto.Changeset
import Ecto.Query

alias Philomena.ImageIntensities.ImageIntensity
alias Philomena.ImageVotes.ImageVote
Expand Down Expand Up @@ -59,14 +58,11 @@ defmodule Philomena.Images.Image do
field :image_is_animated, :boolean, source: :is_animated
field :ip, EctoNetwork.INET
field :fingerprint, :string
field :user_agent, :string, default: ""
field :referrer, :string, default: ""
field :anonymous, :boolean, default: false
field :score, :integer, default: 0
field :faves_count, :integer, default: 0
field :upvotes_count, :integer, default: 0
field :downvotes_count, :integer, default: 0
field :votes_count, :integer, default: 0
field :source_url, :string
field :description, :string, default: ""
field :image_sha512_hash, :string
Expand All @@ -88,11 +84,6 @@ defmodule Philomena.Images.Image do
field :hides_count, :integer, default: 0
field :approved, :boolean

# todo: can probably remove these now
field :tag_list_cache, :string
field :tag_list_plus_alias_cache, :string
field :file_name_cache, :string

field :removed_tags, {:array, :any}, default: [], virtual: true
field :added_tags, {:array, :any}, default: [], virtual: true
field :removed_sources, {:array, :any}, default: [], virtual: true
Expand Down Expand Up @@ -228,7 +219,6 @@ defmodule Philomena.Images.Image do
|> cast(attrs, [])
|> TagDiffer.diff_input(old_tags, new_tags, excluded_tags)
|> TagValidator.validate_tags()
|> cache_changeset()
end

def locked_tags_changeset(image, attrs, locked_tags) do
Expand Down Expand Up @@ -345,53 +335,6 @@ defmodule Philomena.Images.Image do
|> put_change(:first_seen_at, DateTime.utc_now(:second))
end

def cache_changeset(image) do
changeset = change(image)
image = apply_changes(changeset)

{tag_list_cache, tag_list_plus_alias_cache, file_name_cache} =
create_caches(image.id, image.tags)

changeset
|> put_change(:tag_list_cache, tag_list_cache)
|> put_change(:tag_list_plus_alias_cache, tag_list_plus_alias_cache)
|> put_change(:file_name_cache, file_name_cache)
end

defp create_caches(image_id, tags) do
tags = Tag.display_order(tags)

tag_list_cache =
tags
|> Enum.map_join(", ", & &1.name)

tag_ids = tags |> Enum.map(& &1.id)

aliases =
Tag
|> where([t], t.aliased_tag_id in ^tag_ids)
|> Repo.all()

tag_list_plus_alias_cache =
(tags ++ aliases)
|> Tag.display_order()
|> Enum.map_join(", ", & &1.name)

# Truncate filename to 150 characters, making room for the path + filename on Windows
# https://stackoverflow.com/questions/265769/maximum-filename-length-in-ntfs-windows-xp-and-windows-vista
file_name_slug_fragment =
tags
|> Enum.map_join("_", & &1.slug)
|> String.to_charlist()
|> Enum.filter(&(&1 in ?a..?z or &1 in ~c"0123456789_-"))
|> List.to_string()
|> String.slice(0..150)

file_name_cache = "#{image_id}__#{file_name_slug_fragment}"

{tag_list_cache, tag_list_plus_alias_cache, file_name_cache}
end

defp create_key do
Base.encode16(:crypto.strong_rand_bytes(6), case: :lower)
end
Expand Down
8 changes: 0 additions & 8 deletions lib/philomena/notifications/channel_live_notification.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
defmodule Philomena.Notifications.ChannelLiveNotification do
use Ecto.Schema
import Ecto.Changeset

alias Philomena.Users.User
alias Philomena.Channels.Channel
Expand All @@ -15,11 +14,4 @@ defmodule Philomena.Notifications.ChannelLiveNotification do

timestamps(inserted_at: :created_at, type: :utc_datetime)
end

@doc false
def changeset(channel_live_notification, attrs) do
channel_live_notification
|> cast(attrs, [])
|> validate_required([])
end
end
8 changes: 0 additions & 8 deletions lib/philomena/notifications/forum_post_notification.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
defmodule Philomena.Notifications.ForumPostNotification do
use Ecto.Schema
import Ecto.Changeset

alias Philomena.Users.User
alias Philomena.Topics.Topic
Expand All @@ -17,11 +16,4 @@ defmodule Philomena.Notifications.ForumPostNotification do

timestamps(inserted_at: :created_at, type: :utc_datetime)
end

@doc false
def changeset(forum_post_notification, attrs) do
forum_post_notification
|> cast(attrs, [])
|> validate_required([])
end
end
8 changes: 0 additions & 8 deletions lib/philomena/notifications/forum_topic_notification.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
defmodule Philomena.Notifications.ForumTopicNotification do
use Ecto.Schema
import Ecto.Changeset

alias Philomena.Users.User
alias Philomena.Topics.Topic
Expand All @@ -15,11 +14,4 @@ defmodule Philomena.Notifications.ForumTopicNotification do

timestamps(inserted_at: :created_at, type: :utc_datetime)
end

@doc false
def changeset(forum_topic_notification, attrs) do
forum_topic_notification
|> cast(attrs, [])
|> validate_required([])
end
end
8 changes: 0 additions & 8 deletions lib/philomena/notifications/gallery_image_notification.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
defmodule Philomena.Notifications.GalleryImageNotification do
use Ecto.Schema
import Ecto.Changeset

alias Philomena.Users.User
alias Philomena.Galleries.Gallery
Expand All @@ -15,11 +14,4 @@ defmodule Philomena.Notifications.GalleryImageNotification do

timestamps(inserted_at: :created_at, type: :utc_datetime)
end

@doc false
def changeset(gallery_image_notification, attrs) do
gallery_image_notification
|> cast(attrs, [])
|> validate_required([])
end
end
8 changes: 0 additions & 8 deletions lib/philomena/notifications/image_comment_notification.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
defmodule Philomena.Notifications.ImageCommentNotification do
use Ecto.Schema
import Ecto.Changeset

alias Philomena.Users.User
alias Philomena.Images.Image
Expand All @@ -17,11 +16,4 @@ defmodule Philomena.Notifications.ImageCommentNotification do

timestamps(inserted_at: :created_at, type: :utc_datetime)
end

@doc false
def changeset(image_comment_notification, attrs) do
image_comment_notification
|> cast(attrs, [])
|> validate_required([])
end
end
8 changes: 0 additions & 8 deletions lib/philomena/notifications/image_merge_notification.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
defmodule Philomena.Notifications.ImageMergeNotification do
use Ecto.Schema
import Ecto.Changeset

alias Philomena.Users.User
alias Philomena.Images.Image
Expand All @@ -16,11 +15,4 @@ defmodule Philomena.Notifications.ImageMergeNotification do

timestamps(inserted_at: :created_at, type: :utc_datetime)
end

@doc false
def changeset(image_merge_notification, attrs) do
image_merge_notification
|> cast(attrs, [])
|> validate_required([])
end
end
4 changes: 0 additions & 4 deletions lib/philomena/polls/poll.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@ defmodule Philomena.Polls.Poll do
import Ecto.Changeset

alias Philomena.Topics.Topic
alias Philomena.Users.User
alias Philomena.PollOptions.PollOption

schema "polls" do
belongs_to :topic, Topic
belongs_to :deleted_by, User
has_many :options, PollOption

field :title, :string
field :vote_method, :string
field :active_until, PhilomenaQuery.Ecto.RelativeDate
field :total_votes, :integer, default: 0
field :hidden_from_users, :boolean, default: false
field :deletion_reason, :string, default: ""

timestamps(inserted_at: :created_at, type: :utc_datetime)
end
Expand Down
Loading

0 comments on commit 87e8b82

Please sign in to comment.