perf: reuse authorized pull snapshots (Closes #1350)
This commit is contained in:
1 parent
f0f415c65d
commit
b47ed5d86e
3 files changed
+137
-32
No files matched your search
+26
-4
@@ -2836,6 +2836,22 @@ async def pull_workspace_capabilities(repository: str, number: int) -> dict[str,
|
||||
}
|
||||
|
||||
|
||||
async def pull_workspace_snapshot(repository: str, number: int) -> dict:
|
||||
"""Resolve one canonical pull and the access granted by that exact snapshot."""
|
||||
login, pull = await _current_login_and_target(
|
||||
f"repos/{repository}/pulls/{number}"
|
||||
)
|
||||
author = pull.get("user") if isinstance(pull.get("user"), dict) else {}
|
||||
open_pull = pull.get("state") == "open" and pull.get("merged") is not True
|
||||
return {
|
||||
"pull": pull,
|
||||
"capabilities": {
|
||||
"authored": open_pull and author.get("login", "").casefold() == login.casefold(),
|
||||
"assigned": open_pull and _login_in_users(login, pull.get("assignees")),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
async def is_assigned_pull(repository: str, number: int) -> bool:
|
||||
login, pull = await _current_login_and_target(
|
||||
f"repos/{repository}/pulls/{number}"
|
||||
@@ -2891,9 +2907,12 @@ async def update_authored_assigned_pull(
|
||||
}
|
||||
|
||||
|
||||
async def pull_completion_detail(repository: str, number: int) -> dict:
|
||||
async def pull_completion_detail(
|
||||
repository: str, number: int, pull: dict | None = None
|
||||
) -> dict:
|
||||
base = f"repos/{repository}/pulls/{number}"
|
||||
pull = await fetch(base)
|
||||
if pull is None:
|
||||
pull = await fetch(base)
|
||||
if not isinstance(pull, dict):
|
||||
raise ValueError("Gitea pull request response was not an object")
|
||||
conversation = await issue_conversation_page(repository, number)
|
||||
@@ -3013,9 +3032,12 @@ def _normalize_reviewer_statuses(pull: dict, reviews: object, head_sha: str) ->
|
||||
return sorted(statuses.values(), key=lambda item: item["login"].casefold())
|
||||
|
||||
|
||||
async def pull_completion_review(repository: str, number: int) -> dict:
|
||||
async def pull_completion_review(
|
||||
repository: str, number: int, pull: dict | None = None
|
||||
) -> dict:
|
||||
base = f"repos/{repository}/pulls/{number}"
|
||||
pull = await fetch(base)
|
||||
if pull is None:
|
||||
pull = await fetch(base)
|
||||
if not isinstance(pull, dict):
|
||||
raise ValueError("Gitea pull request response was not an object")
|
||||
head_value = pull.get("head")
|
||||
|
||||
+10
-4
@@ -6576,10 +6576,13 @@ async def assigned_pull_detail(owner: str, repo: str, number: int = PathParam(gt
|
||||
repository = f"{owner}/{repo}"
|
||||
|
||||
async def load_assigned_pull():
|
||||
capabilities = await _pull_workspace_capabilities(repository, number)
|
||||
snapshot = await gitea_proxy.pull_workspace_snapshot(repository, number)
|
||||
capabilities = snapshot["capabilities"]
|
||||
if not _has_pull_workspace_access(capabilities):
|
||||
raise HTTPException(status_code=404, detail="Pull request not found")
|
||||
detail = await gitea_proxy.pull_completion_detail(repository, number)
|
||||
detail = await gitea_proxy.pull_completion_detail(
|
||||
repository, number, snapshot["pull"]
|
||||
)
|
||||
return {**detail, "capabilities": capabilities}
|
||||
|
||||
try:
|
||||
@@ -6673,10 +6676,13 @@ async def assigned_pull_review_data(
|
||||
repository = f"{owner}/{repo}"
|
||||
|
||||
async def load_assigned_pull_review():
|
||||
capabilities = await _pull_workspace_capabilities(repository, number)
|
||||
snapshot = await gitea_proxy.pull_workspace_snapshot(repository, number)
|
||||
capabilities = snapshot["capabilities"]
|
||||
if not _has_pull_workspace_access(capabilities):
|
||||
raise HTTPException(status_code=404, detail="Pull request not found")
|
||||
review = await gitea_proxy.pull_completion_review(repository, number)
|
||||
review = await gitea_proxy.pull_completion_review(
|
||||
repository, number, snapshot["pull"]
|
||||
)
|
||||
return {**review, "capabilities": capabilities}
|
||||
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user