Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 7f46b98

Browse files
committed
Cache and trace fetching the commit yaml
1 parent 7c058c9 commit 7f46b98

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

services/yaml.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import enum
22
import logging
33
from functools import lru_cache
4-
from typing import Dict, Optional
54

5+
import sentry_sdk
66
from asgiref.sync import async_to_sync
7+
from shared.helpers.cache import OurOwnCache
78
from shared.yaml import UserYaml, fetch_current_yaml_from_provider_via_reference
89
from shared.yaml.validation import validate_yaml
910
from yaml import safe_load
@@ -12,6 +13,8 @@
1213
from core.models import Commit
1314
from services.repo_providers import RepoProviderService
1415

16+
cache = OurOwnCache()
17+
1518

1619
class YamlStates(enum.Enum):
1720
DEFAULT = "default"
@@ -20,7 +23,8 @@ class YamlStates(enum.Enum):
2023
log = logging.getLogger(__name__)
2124

2225

23-
def fetch_commit_yaml(commit: Commit, owner: Owner | None) -> Dict | None:
26+
@cache.cache_function(ttl=60 * 60)
27+
def fetch_commit_yaml(commit: Commit, owner: Owner | None) -> dict | None:
2428
"""
2529
Fetches the codecov.yaml file for a particular commit from the service provider.
2630
Service provider API request is made on behalf of the given `owner`.
@@ -61,7 +65,7 @@ def fetch_commit_yaml(commit: Commit, owner: Owner | None) -> Dict | None:
6165

6266

6367
@lru_cache()
64-
# TODO: make this use the Redis cache logic in 'shared' once it's there
68+
@sentry_sdk.trace
6569
def final_commit_yaml(commit: Commit, owner: Owner | None) -> UserYaml:
6670
return UserYaml.get_final_yaml(
6771
owner_yaml=commit.repository.author.yaml,
@@ -70,6 +74,6 @@ def final_commit_yaml(commit: Commit, owner: Owner | None) -> UserYaml:
7074
)
7175

7276

73-
def get_yaml_state(yaml: UserYaml) -> Optional[YamlStates]:
77+
def get_yaml_state(yaml: UserYaml) -> YamlStates | None:
7478
if yaml == get_config("site", default={}):
7579
return YamlStates.DEFAULT

0 commit comments

Comments
 (0)