Optimization
This commit is contained in:
@@ -545,6 +545,28 @@ async def remove_gitea_asset(row):
|
||||
logger.warning("Gitea asset delete failed for %s: %s", row.get("uid"), exc)
|
||||
|
||||
|
||||
_pending_gitea_tasks: set[asyncio.Task] = set()
|
||||
|
||||
|
||||
def _fire_and_forget(coro) -> None:
|
||||
try:
|
||||
loop = asyncio.get_running_loop()
|
||||
except RuntimeError:
|
||||
coro.close()
|
||||
return
|
||||
task = loop.create_task(coro)
|
||||
_pending_gitea_tasks.add(task)
|
||||
task.add_done_callback(_pending_gitea_tasks.discard)
|
||||
|
||||
|
||||
def schedule_gitea_mirror(uid: str) -> None:
|
||||
_fire_and_forget(mirror_attachment_to_gitea(uid))
|
||||
|
||||
|
||||
def schedule_gitea_removal(row: dict) -> None:
|
||||
_fire_and_forget(remove_gitea_asset(row))
|
||||
|
||||
|
||||
def _unlink_attachment_files(row):
|
||||
stored_name = row.get("stored_name", "")
|
||||
directory = row.get("directory", "")
|
||||
|
||||
@@ -10,8 +10,8 @@ from devplacepy.attachments import (
|
||||
get_attachments,
|
||||
get_orphan_attachments_batch,
|
||||
link_attachments,
|
||||
mirror_attachment_to_gitea,
|
||||
remove_gitea_asset,
|
||||
schedule_gitea_mirror,
|
||||
schedule_gitea_removal,
|
||||
soft_delete_attachment,
|
||||
split_attachment_uids,
|
||||
)
|
||||
@@ -96,7 +96,7 @@ async def add_issue_attachment(
|
||||
return json_error(400, "No valid attachments to add")
|
||||
link_attachments(owned, "issue", str(number))
|
||||
for uid in owned:
|
||||
await mirror_attachment_to_gitea(uid)
|
||||
schedule_gitea_mirror(uid)
|
||||
audit.record(
|
||||
request,
|
||||
"issue.attachment.add",
|
||||
@@ -146,7 +146,7 @@ async def delete_issue_attachment(request: Request, number: int, uid: str):
|
||||
)
|
||||
return json_error(409, "Attachments cannot be changed on a closed issue")
|
||||
soft_delete_attachment(uid, deleted_by=user["uid"])
|
||||
await remove_gitea_asset(att)
|
||||
schedule_gitea_removal(att)
|
||||
audit.record(
|
||||
request,
|
||||
"issue.attachment.delete",
|
||||
@@ -194,7 +194,7 @@ async def add_comment_attachment(
|
||||
return json_error(400, "No valid attachments to add")
|
||||
link_attachments(owned, "issue_comment", str(cid))
|
||||
for uid in owned:
|
||||
await mirror_attachment_to_gitea(uid)
|
||||
schedule_gitea_mirror(uid)
|
||||
audit.record(
|
||||
request,
|
||||
"issue.attachment.add",
|
||||
@@ -237,7 +237,7 @@ async def delete_comment_attachment(
|
||||
if issue.get("state") != STATE_OPEN:
|
||||
return json_error(409, "Attachments cannot be changed on a closed issue")
|
||||
soft_delete_attachment(uid, deleted_by=user["uid"])
|
||||
await remove_gitea_asset(att)
|
||||
schedule_gitea_removal(att)
|
||||
audit.record(
|
||||
request,
|
||||
"issue.attachment.delete",
|
||||
|
||||
@@ -8,7 +8,7 @@ from fastapi import Depends, APIRouter, Request
|
||||
from devplacepy.attachments import (
|
||||
get_orphan_attachments_batch,
|
||||
link_attachments,
|
||||
mirror_attachment_to_gitea,
|
||||
schedule_gitea_mirror,
|
||||
split_attachment_uids,
|
||||
)
|
||||
from devplacepy.database import get_table
|
||||
@@ -73,7 +73,7 @@ async def comment_issue(
|
||||
if owned:
|
||||
link_attachments(owned, "issue_comment", str(comment_id))
|
||||
for uid in owned:
|
||||
await mirror_attachment_to_gitea(uid)
|
||||
schedule_gitea_mirror(uid)
|
||||
background.submit(_notify_admins, user, number)
|
||||
audit.record(
|
||||
request,
|
||||
|
||||
Reference in New Issue
Block a user