11import enum
22import logging
33from functools import lru_cache
4- from typing import Dict , Optional
54
5+ import sentry_sdk
66from asgiref .sync import async_to_sync
7+ from shared .helpers .cache import OurOwnCache
78from shared .yaml import UserYaml , fetch_current_yaml_from_provider_via_reference
89from shared .yaml .validation import validate_yaml
910from yaml import safe_load
1213from core .models import Commit
1314from services .repo_providers import RepoProviderService
1415
16+ cache = OurOwnCache ()
17+
1518
1619class YamlStates (enum .Enum ):
1720 DEFAULT = "default"
@@ -20,7 +23,8 @@ class YamlStates(enum.Enum):
2023log = 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
6569def 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