fix(publish): idempotent approve and visible result on selected page
This commit is contained in:
@@ -20,6 +20,26 @@ def impl_approve(post_id: int, comment: str = "", dirs_selected: list[str] | Non
|
||||
conn.close()
|
||||
return "notfound"
|
||||
post = dict(post)
|
||||
|
||||
# Атомарный захват: повторный клик не должен публиковать второй раз (баг #3575 — 5 публикаций).
|
||||
# Статус меняет только один запрос; остальные видят published/publishing и получают отказ.
|
||||
prev_status = post.get("status") or "new"
|
||||
claimed = conn.execute(
|
||||
"UPDATE posts SET status='publishing' WHERE id=? AND status IN ('new','selected','queued')",
|
||||
(post_id,),
|
||||
).rowcount
|
||||
conn.commit()
|
||||
if not claimed:
|
||||
row = conn.execute("SELECT status FROM posts WHERE id=?", (post_id,)).fetchone()
|
||||
conn.close()
|
||||
status = (row["status"] if row else "") or ""
|
||||
return "already" if status == "published" else f"busy:{status}"
|
||||
|
||||
def _release(status: str = prev_status) -> None:
|
||||
"""Возвращает пост в прежний статус (не оставляем в publishing)."""
|
||||
conn.execute("UPDATE posts SET status=? WHERE id=? AND status='publishing'", (status, post_id))
|
||||
conn.commit()
|
||||
|
||||
is_own = int(post.get("is_own") or 0) == 1
|
||||
dirn = post.get("direction") or "linux"
|
||||
lang = post.get("lang") or "ru"
|
||||
@@ -37,6 +57,7 @@ def impl_approve(post_id: int, comment: str = "", dirs_selected: list[str] | Non
|
||||
try:
|
||||
res = http_publish(card)
|
||||
except RuntimeError as e:
|
||||
_release()
|
||||
conn.close()
|
||||
return f"publisher:{e}"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user