From c65f27a1ff1b5b75a92b41600ea97595d1a37c43 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Mon, 6 Jul 2020 14:12:18 -0400 Subject: [PATCH] mix format --- lib/philomena/elasticsearch.ex | 4 +- lib/philomena/processors/png.ex | 22 ++++++- lib/philomena/scrapers/twitter.ex | 4 +- .../image/description_controller.ex | 8 ++- .../controllers/image/source_controller.ex | 1 + .../controllers/image/tag_controller.ex | 7 +- ...0617111116_prod_schema_sync_2020_06_17.exs | 65 +++++++++++++++---- .../20200617113333_prod_schema_sync2.exs | 6 +- 8 files changed, 98 insertions(+), 19 deletions(-) diff --git a/lib/philomena/elasticsearch.ex b/lib/philomena/elasticsearch.ex index 9374ce47..62b56590 100644 --- a/lib/philomena/elasticsearch.ex +++ b/lib/philomena/elasticsearch.ex @@ -52,7 +52,9 @@ defmodule Philomena.Elasticsearch do index_name = index.index_name() mapping = index.mapping().mappings.properties - Elastix.Mapping.put(elastic_url(), index_name, "_doc", %{properties: mapping}, include_type_name: true) + Elastix.Mapping.put(elastic_url(), index_name, "_doc", %{properties: mapping}, + include_type_name: true + ) end def index_document(doc, module) do diff --git a/lib/philomena/processors/png.ex b/lib/philomena/processors/png.ex index 5a536dca..1b1d5fc2 100644 --- a/lib/philomena/processors/png.ex +++ b/lib/philomena/processors/png.ex @@ -40,7 +40,12 @@ defmodule Philomena.Processors.Png do [{:symlink_original, "full.png"}] end - defp scale_if_smaller(file, animated?, {width, height}, {thumb_name, {target_width, target_height}}) do + defp scale_if_smaller( + file, + animated?, + {width, height}, + {thumb_name, {target_width, target_height}} + ) do if width > target_width or height > target_height do scaled = scale(file, animated?, {target_width, target_height}) @@ -59,7 +64,20 @@ defmodule Philomena.Processors.Png do {_output, 0} = cond do animated? -> - System.cmd("ffmpeg", ["-loglevel", "0", "-y", "-i", file, "-plays", "0", "-vf", scale_filter, "-f", "apng", scaled]) + System.cmd("ffmpeg", [ + "-loglevel", + "0", + "-y", + "-i", + file, + "-plays", + "0", + "-vf", + scale_filter, + "-f", + "apng", + scaled + ]) true -> System.cmd("ffmpeg", ["-loglevel", "0", "-y", "-i", file, "-vf", scale_filter, scaled]) diff --git a/lib/philomena/scrapers/twitter.ex b/lib/philomena/scrapers/twitter.ex index 38eaeb64..36e8ea5b 100644 --- a/lib/philomena/scrapers/twitter.ex +++ b/lib/philomena/scrapers/twitter.ex @@ -60,7 +60,9 @@ defmodule Philomena.Scrapers.Twitter do end defp extract_guest_token_and_bearer(%Tesla.Env{body: page, headers: headers}) do - [{_, gt}] = Enum.filter(headers, fn {k, v} -> k == "set-cookie" and String.starts_with?(v, "gt=") end) + [{_, gt}] = + Enum.filter(headers, fn {k, v} -> k == "set-cookie" and String.starts_with?(v, "gt=") end) + [gt] = Regex.run(@gt_regex, gt, capture: :all_but_first) [script] = Regex.run(@script_regex, page, capture: :all_but_first) diff --git a/lib/philomena_web/controllers/image/description_controller.ex b/lib/philomena_web/controllers/image/description_controller.ex index b249ba4c..d6ea745a 100644 --- a/lib/philomena_web/controllers/image/description_controller.ex +++ b/lib/philomena_web/controllers/image/description_controller.ex @@ -7,7 +7,12 @@ defmodule PhilomenaWeb.Image.DescriptionController do plug PhilomenaWeb.FilterBannedUsersPlug plug PhilomenaWeb.CanaryMapPlug, update: :edit_description - plug :load_and_authorize_resource, model: Image, id_name: "image_id", persisted: true, preload: [:tags, :user] + + plug :load_and_authorize_resource, + model: Image, + id_name: "image_id", + persisted: true, + preload: [:tags, :user] def update(conn, %{"image" => image_params}) do image = conn.assigns.image @@ -20,6 +25,7 @@ defmodule PhilomenaWeb.Image.DescriptionController do "image:description_update", %{image_id: image.id, added: image.description, removed: old_description} ) + PhilomenaWeb.Endpoint.broadcast!( "firehose", "image:update", diff --git a/lib/philomena_web/controllers/image/source_controller.ex b/lib/philomena_web/controllers/image/source_controller.ex index 729e7466..0d4c58cd 100644 --- a/lib/philomena_web/controllers/image/source_controller.ex +++ b/lib/philomena_web/controllers/image/source_controller.ex @@ -26,6 +26,7 @@ defmodule PhilomenaWeb.Image.SourceController do "image:source_update", %{image_id: image.id, added: [image.source_url], removed: [old_source]} ) + PhilomenaWeb.Endpoint.broadcast!( "firehose", "image:update", diff --git a/lib/philomena_web/controllers/image/tag_controller.ex b/lib/philomena_web/controllers/image/tag_controller.ex index f80acdc7..b987f983 100644 --- a/lib/philomena_web/controllers/image/tag_controller.ex +++ b/lib/philomena_web/controllers/image/tag_controller.ex @@ -25,8 +25,13 @@ defmodule PhilomenaWeb.Image.TagController do PhilomenaWeb.Endpoint.broadcast!( "firehose", "image:tag_update", - %{image_id: image.id, added: Enum.map(added_tags, & &1.name), removed: Enum.map(removed_tags, & &1.name)} + %{ + image_id: image.id, + added: Enum.map(added_tags, & &1.name), + removed: Enum.map(removed_tags, & &1.name) + } ) + PhilomenaWeb.Endpoint.broadcast!( "firehose", "image:update", diff --git a/priv/repo/migrations/20200617111116_prod_schema_sync_2020_06_17.exs b/priv/repo/migrations/20200617111116_prod_schema_sync_2020_06_17.exs index 4e8d5c7c..9fc49f66 100644 --- a/priv/repo/migrations/20200617111116_prod_schema_sync_2020_06_17.exs +++ b/priv/repo/migrations/20200617111116_prod_schema_sync_2020_06_17.exs @@ -2,32 +2,73 @@ defmodule Philomena.Repo.Migrations.ProdSchemaSync20200617 do use Ecto.Migration def change do - execute("CREATE INDEX index_comments_on_image_id_and_created_at ON public.comments USING btree (image_id, created_at);") + execute( + "CREATE INDEX index_comments_on_image_id_and_created_at ON public.comments USING btree (image_id, created_at);" + ) + execute("DROP INDEX index_dnp_entries_on_modifying_user_id;") - execute("CREATE INDEX index_dnp_entries_on_aasm_state_filtered ON public.dnp_entries USING btree (aasm_state) WHERE ((aasm_state)::text = ANY (ARRAY[('requested'::character varying)::text, ('claimed'::character varying)::text, ('rescinded'::character varying)::text, ('acknowledged'::character varying)::text]));") - execute("CREATE INDEX index_duplicate_reports_on_state_filtered ON public.duplicate_reports USING btree (state) WHERE ((state)::text = ANY (ARRAY[('open'::character varying)::text, ('claimed'::character varying)::text]));") + + execute( + "CREATE INDEX index_dnp_entries_on_aasm_state_filtered ON public.dnp_entries USING btree (aasm_state) WHERE ((aasm_state)::text = ANY (ARRAY[('requested'::character varying)::text, ('claimed'::character varying)::text, ('rescinded'::character varying)::text, ('acknowledged'::character varying)::text]));" + ) + + execute( + "CREATE INDEX index_duplicate_reports_on_state_filtered ON public.duplicate_reports USING btree (state) WHERE ((state)::text = ANY (ARRAY[('open'::character varying)::text, ('claimed'::character varying)::text]));" + ) + execute("CREATE INDEX index_filters_on_name ON public.filters USING btree (name);") - execute("CREATE INDEX index_filters_on_system ON public.filters USING btree (system) WHERE (system = true);") - execute("CREATE UNIQUE INDEX index_gallery_interactions_on_gallery_id_and_image_id ON public.gallery_interactions USING btree (gallery_id, image_id);") - execute("CREATE INDEX index_gallery_interactions_on_gallery_id_and_position ON public.gallery_interactions USING btree (gallery_id, \"position\");") + + execute( + "CREATE INDEX index_filters_on_system ON public.filters USING btree (system) WHERE (system = true);" + ) + + execute( + "CREATE UNIQUE INDEX index_gallery_interactions_on_gallery_id_and_image_id ON public.gallery_interactions USING btree (gallery_id, image_id);" + ) + + execute( + "CREATE INDEX index_gallery_interactions_on_gallery_id_and_position ON public.gallery_interactions USING btree (gallery_id, \"position\");" + ) + execute("DROP INDEX index_images_on_first_seen_at;") execute("DROP INDEX index_notifications_on_actor_id_and_actor_type;") - execute("CREATE UNIQUE INDEX index_notifications_on_actor_id_and_actor_type ON public.notifications USING btree (actor_id, actor_type);") - execute("CREATE INDEX index_subnet_bans_on_specification ON public.subnet_bans USING gist (specification inet_ops);") - execute("CREATE INDEX index_tag_changes_on_fingerprint ON public.tag_changes USING btree (fingerprint);") - execute("CREATE INDEX index_tag_changes_on_ip ON public.tag_changes USING gist (ip inet_ops);") + + execute( + "CREATE UNIQUE INDEX index_notifications_on_actor_id_and_actor_type ON public.notifications USING btree (actor_id, actor_type);" + ) + + execute( + "CREATE INDEX index_subnet_bans_on_specification ON public.subnet_bans USING gist (specification inet_ops);" + ) + + execute( + "CREATE INDEX index_tag_changes_on_fingerprint ON public.tag_changes USING btree (fingerprint);" + ) + + execute( + "CREATE INDEX index_tag_changes_on_ip ON public.tag_changes USING gist (ip inet_ops);" + ) + execute("DROP INDEX index_tags_on_name;") execute("CREATE UNIQUE INDEX index_tags_on_name ON public.tags USING btree (name);") execute("DROP INDEX index_tags_on_slug;") execute("CREATE UNIQUE INDEX index_tags_on_slug ON public.tags USING btree (slug);") execute("DROP INDEX index_topics_on_sticky;") execute("DROP INDEX index_user_bans_on_created_at;") - execute("CREATE INDEX index_user_bans_on_created_at ON public.user_bans USING btree (created_at DESC);") + + execute( + "CREATE INDEX index_user_bans_on_created_at ON public.user_bans USING btree (created_at DESC);" + ) + execute("DROP INDEX index_users_on_name;") execute("CREATE UNIQUE INDEX index_users_on_name ON public.users USING btree (name);") execute("DROP INDEX index_users_on_slug;") execute("CREATE UNIQUE INDEX index_users_on_slug ON public.users USING btree (slug)") - execute("CREATE INDEX index_users_on_watched_tag_ids ON public.users USING gin (watched_tag_ids);") + + execute( + "CREATE INDEX index_users_on_watched_tag_ids ON public.users USING gin (watched_tag_ids);" + ) + execute("DROP INDEX index_adverts_on_live;") execute("DROP INDEX index_commissions_on_categories;") end diff --git a/priv/repo/migrations/20200617113333_prod_schema_sync2.exs b/priv/repo/migrations/20200617113333_prod_schema_sync2.exs index dc5466af..87f787bc 100644 --- a/priv/repo/migrations/20200617113333_prod_schema_sync2.exs +++ b/priv/repo/migrations/20200617113333_prod_schema_sync2.exs @@ -46,7 +46,11 @@ defmodule Philomena.Repo.Migrations.ProdSchemaSync2 do execute("ALTER SEQUENCE users_id_seq AS BIGINT;") execute("ALTER SEQUENCE versions_id_seq AS BIGINT;") execute("CREATE INDEX index_users_on_created_at ON public.users USING btree (created_at);") - execute("CREATE INDEX index_users_on_role ON public.users USING btree (role) WHERE ((role)::text <> 'user'::text);") + + execute( + "CREATE INDEX index_users_on_role ON public.users USING btree (role) WHERE ((role)::text <> 'user'::text);" + ) + execute("DROP INDEX temp_unique_index_tags_on_name;") execute("DROP INDEX temp_unique_index_tags_on_slug;") end