|
7 | 7 | from pathlib import Path |
8 | 8 | from typing import TYPE_CHECKING, Any, Optional |
9 | 9 |
|
| 10 | +import git |
10 | 11 | import requests |
11 | 12 | import sentry_sdk |
12 | 13 | from pydantic.json import pydantic_encoder |
@@ -191,3 +192,35 @@ def get_blocklisted_functions() -> dict[str, set[str]] | dict[str, Any]: |
191 | 192 | return {} |
192 | 193 |
|
193 | 194 | return {Path(k).name: {v.replace("()", "") for v in values} for k, values in content.items()} |
| 195 | + |
| 196 | + |
| 197 | +def is_function_being_optimized_again( |
| 198 | + owner: str, repo: str, pr_number: int, code_contexts: list[dict[str, str]] |
| 199 | +) -> Any: # noqa: ANN401 |
| 200 | + """Check if the function being optimized is being optimized again.""" |
| 201 | + response = make_cfapi_request( |
| 202 | + "/is-already-optimized", |
| 203 | + "POST", |
| 204 | + {"owner": owner, "repo": repo, "pr_number": pr_number, "code_contexts": code_contexts}, |
| 205 | + ) |
| 206 | + response.raise_for_status() |
| 207 | + return response.json() |
| 208 | + |
| 209 | + |
| 210 | +def add_code_context_hash(code_context_hash: str) -> None: |
| 211 | + """Add code context to the DB cache.""" |
| 212 | + pr_number = get_pr_number() |
| 213 | + if pr_number is None: |
| 214 | + return |
| 215 | + try: |
| 216 | + owner, repo = get_repo_owner_and_name() |
| 217 | + pr_number = get_pr_number() |
| 218 | + except git.exc.InvalidGitRepositoryError: |
| 219 | + return |
| 220 | + |
| 221 | + if owner and repo and pr_number is not None: |
| 222 | + make_cfapi_request( |
| 223 | + "/add-code-hash", |
| 224 | + "POST", |
| 225 | + {"owner": owner, "repo": repo, "pr_number": pr_number, "code_hash": code_context_hash}, |
| 226 | + ) |
0 commit comments