from anydi import singleton from cachelib import BaseCache as Cache from fansifter_common.adapters.ows_account import OwsAccountClient from fansifter_common.utils.cache import cached from ows_text_campaigns.rosters.constants import GLOBAL_FAN_DATA_LISTS_FEATURE_ID from ows_text_campaigns.rosters.repositories import ArtistRosterMainRepRepository DEFAULT_CACHE_TIMEOUT = 60 * 10 # 10 minutes @singleton class GlobalFanDataAccessService: def __init__( self, ows_account_client: OwsAccountClient, artist_roster_main_rep_repository: ArtistRosterMainRepRepository, cache: Cache, ) -> None: self.ows_account_client = ows_account_client self.artist_roster_main_rep_repository = artist_roster_main_rep_repository self.cache = cache @cached("global-fandata-list-enabled-for-vendor", timeout=DEFAULT_CACHE_TIMEOUT) def is_enabled_for_vendor(self, vendor_id: int) -> bool: features = self.ows_account_client.get_vendor_features(vendor_id) for feature in features: if feature.feature_id == GLOBAL_FAN_DATA_LISTS_FEATURE_ID: return True return False