mirror of
https://github.com/Dictionarry-Hub/profilarr.git
synced 2026-01-22 10:51:02 +01:00
perf(cache): add proper file caching at the import instantiation
This commit is contained in:
@@ -12,7 +12,8 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
def compile_format_to_api_structure(
|
def compile_format_to_api_structure(
|
||||||
format_yaml: Dict[str, Any],
|
format_yaml: Dict[str, Any],
|
||||||
arr_type: str
|
arr_type: str,
|
||||||
|
patterns: Dict[str, str] = None
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Compile a format from YAML to Arr API structure.
|
Compile a format from YAML to Arr API structure.
|
||||||
@@ -20,12 +21,15 @@ def compile_format_to_api_structure(
|
|||||||
Args:
|
Args:
|
||||||
format_yaml: Format data from YAML file
|
format_yaml: Format data from YAML file
|
||||||
arr_type: 'radarr' or 'sonarr'
|
arr_type: 'radarr' or 'sonarr'
|
||||||
|
patterns: Pre-loaded regex patterns (if None, will load from disk)
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Compiled format ready for API
|
Compiled format ready for API
|
||||||
"""
|
"""
|
||||||
target_app = TargetApp.RADARR if arr_type.lower() == 'radarr' else TargetApp.SONARR
|
target_app = TargetApp.RADARR if arr_type.lower() == 'radarr' else TargetApp.SONARR
|
||||||
patterns = load_regex_patterns()
|
# Only load patterns if not provided
|
||||||
|
if patterns is None:
|
||||||
|
patterns = load_regex_patterns()
|
||||||
|
|
||||||
compiled = {
|
compiled = {
|
||||||
'name': format_yaml.get('name', 'Unknown')
|
'name': format_yaml.get('name', 'Unknown')
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ class FormatStrategy(ImportStrategy):
|
|||||||
Returns:
|
Returns:
|
||||||
Dictionary with 'formats' key containing compiled formats
|
Dictionary with 'formats' key containing compiled formats
|
||||||
"""
|
"""
|
||||||
|
from ..utils import load_regex_patterns
|
||||||
|
|
||||||
|
# Load all regex patterns once at the start
|
||||||
|
patterns = load_regex_patterns()
|
||||||
|
|
||||||
formats = []
|
formats = []
|
||||||
failed = []
|
failed = []
|
||||||
import_logger = get_import_logger()
|
import_logger = get_import_logger()
|
||||||
@@ -35,7 +40,7 @@ class FormatStrategy(ImportStrategy):
|
|||||||
format_yaml = load_yaml(f"custom_format/{filename}.yml")
|
format_yaml = load_yaml(f"custom_format/{filename}.yml")
|
||||||
|
|
||||||
# Compile to API structure
|
# Compile to API structure
|
||||||
compiled = compile_format_to_api_structure(format_yaml, self.arr_type)
|
compiled = compile_format_to_api_structure(format_yaml, self.arr_type, patterns)
|
||||||
|
|
||||||
# Add unique suffix if needed
|
# Add unique suffix if needed
|
||||||
if self.import_as_unique:
|
if self.import_as_unique:
|
||||||
|
|||||||
@@ -22,6 +22,11 @@ class ProfileStrategy(ImportStrategy):
|
|||||||
Returns:
|
Returns:
|
||||||
Dictionary with 'profiles' and 'formats' keys
|
Dictionary with 'profiles' and 'formats' keys
|
||||||
"""
|
"""
|
||||||
|
from ..utils import load_regex_patterns
|
||||||
|
|
||||||
|
# Load all regex patterns once at the start
|
||||||
|
patterns = load_regex_patterns()
|
||||||
|
|
||||||
profiles = []
|
profiles = []
|
||||||
all_formats = []
|
all_formats = []
|
||||||
processed_formats: Set[str] = set()
|
processed_formats: Set[str] = set()
|
||||||
@@ -49,7 +54,7 @@ class ProfileStrategy(ImportStrategy):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
format_yaml = load_yaml(f"custom_format/{format_name}.yml")
|
format_yaml = load_yaml(f"custom_format/{format_name}.yml")
|
||||||
compiled_format = compile_format_to_api_structure(format_yaml, self.arr_type)
|
compiled_format = compile_format_to_api_structure(format_yaml, self.arr_type, patterns)
|
||||||
|
|
||||||
if self.import_as_unique:
|
if self.import_as_unique:
|
||||||
compiled_format['name'] = self.add_unique_suffix(compiled_format['name'])
|
compiled_format['name'] = self.add_unique_suffix(compiled_format['name'])
|
||||||
@@ -72,7 +77,7 @@ class ProfileStrategy(ImportStrategy):
|
|||||||
|
|
||||||
for lang_format in language_formats:
|
for lang_format in language_formats:
|
||||||
lang_name = lang_format.get('name', 'Language format')
|
lang_name = lang_format.get('name', 'Language format')
|
||||||
compiled_lang = compile_format_to_api_structure(lang_format, self.arr_type)
|
compiled_lang = compile_format_to_api_structure(lang_format, self.arr_type, patterns)
|
||||||
|
|
||||||
if self.import_as_unique:
|
if self.import_as_unique:
|
||||||
compiled_lang['name'] = self.add_unique_suffix(compiled_lang['name'])
|
compiled_lang['name'] = self.add_unique_suffix(compiled_lang['name'])
|
||||||
|
|||||||
Reference in New Issue
Block a user