use correct preview endpoint, ensure changes were made before updating stat

This commit is contained in:
byte[] 2019-12-09 14:22:58 -05:00
parent eef6da6c78
commit 16843ec216
3 changed files with 9 additions and 5 deletions

View file

@ -38,8 +38,6 @@ function commentReply(user, url, textarea, quote) {
function getPreview(body, anonymous, previewTab, isImage = false) { function getPreview(body, anonymous, previewTab, isImage = false) {
let path = '/posts/preview'; let path = '/posts/preview';
if (isImage) path = '/images/preview';
fetchJson('POST', path, { body, anonymous }) fetchJson('POST', path, { body, anonymous })
.then(handleError) .then(handleError)
.then(data => { .then(data => {
@ -85,4 +83,4 @@ function setupPreviews() {
}); });
} }
export { setupPreviews }; export { setupPreviews };

View file

@ -17,6 +17,7 @@ defmodule PhilomenaWeb.Image.SourceController do
def update(conn, %{"image" => image_params}) do def update(conn, %{"image" => image_params}) do
attributes = conn.assigns.attributes attributes = conn.assigns.attributes
image = conn.assigns.image image = conn.assigns.image
old_source = image.source_url
case Images.update_source(image, attributes, image_params) do case Images.update_source(image, attributes, image_params) do
{:ok, %{image: image}} -> {:ok, %{image: image}} ->
@ -28,7 +29,9 @@ defmodule PhilomenaWeb.Image.SourceController do
|> where(image_id: ^image.id) |> where(image_id: ^image.id)
|> Repo.aggregate(:count, :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 conn
|> put_view(PhilomenaWeb.ImageView) |> put_view(PhilomenaWeb.ImageView)

View file

@ -23,7 +23,10 @@ defmodule PhilomenaWeb.Image.TagController do
{:ok, %{image: {image, added_tags, removed_tags}}} -> {:ok, %{image: {image, added_tags, removed_tags}}} ->
Images.reindex_image(image) Images.reindex_image(image)
Tags.reindex_tags(added_tags ++ removed_tags) 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 = tag_change_count =
TagChange TagChange