From 16843ec216714357d465d15ff5326d34f47dbbc4 Mon Sep 17 00:00:00 2001 From: "byte[]" Date: Mon, 9 Dec 2019 14:22:58 -0500 Subject: [PATCH] use correct preview endpoint, ensure changes were made before updating stat --- assets/js/preview.js | 4 +--- lib/philomena_web/controllers/image/source_controller.ex | 5 ++++- lib/philomena_web/controllers/image/tag_controller.ex | 5 ++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/assets/js/preview.js b/assets/js/preview.js index c071591f..068120ba 100644 --- a/assets/js/preview.js +++ b/assets/js/preview.js @@ -38,8 +38,6 @@ function commentReply(user, url, textarea, quote) { function getPreview(body, anonymous, previewTab, isImage = false) { let path = '/posts/preview'; - if (isImage) path = '/images/preview'; - fetchJson('POST', path, { body, anonymous }) .then(handleError) .then(data => { @@ -85,4 +83,4 @@ function setupPreviews() { }); } -export { setupPreviews }; +export { setupPreviews }; \ No newline at end of file diff --git a/lib/philomena_web/controllers/image/source_controller.ex b/lib/philomena_web/controllers/image/source_controller.ex index f35bae9a..560b06e4 100644 --- a/lib/philomena_web/controllers/image/source_controller.ex +++ b/lib/philomena_web/controllers/image/source_controller.ex @@ -17,6 +17,7 @@ defmodule PhilomenaWeb.Image.SourceController do def update(conn, %{"image" => image_params}) do attributes = conn.assigns.attributes image = conn.assigns.image + old_source = image.source_url case Images.update_source(image, attributes, image_params) do {:ok, %{image: image}} -> @@ -28,7 +29,9 @@ defmodule PhilomenaWeb.Image.SourceController do |> where(image_id: ^image.id) |> Repo.aggregate(:count, :id) - UserStatistics.inc_stat(conn.assigns.current_user, :metadata_updates) + if old_source != image.source_url do + UserStatistics.inc_stat(conn.assigns.current_user, :metadata_updates) + end conn |> put_view(PhilomenaWeb.ImageView) diff --git a/lib/philomena_web/controllers/image/tag_controller.ex b/lib/philomena_web/controllers/image/tag_controller.ex index fd2d6094..4c703e28 100644 --- a/lib/philomena_web/controllers/image/tag_controller.ex +++ b/lib/philomena_web/controllers/image/tag_controller.ex @@ -23,7 +23,10 @@ defmodule PhilomenaWeb.Image.TagController do {:ok, %{image: {image, added_tags, removed_tags}}} -> Images.reindex_image(image) Tags.reindex_tags(added_tags ++ removed_tags) - UserStatistics.inc_stat(conn.assigns.current_user, :metadata_updates) + + if Enum.any?(added_tags ++ removed_tags) do + UserStatistics.inc_stat(conn.assigns.current_user, :metadata_updates) + end tag_change_count = TagChange