diff --git a/addon_imps/storage/owncloud.py b/addon_imps/storage/owncloud.py index 70b0e77f..832b3c5b 100644 --- a/addon_imps/storage/owncloud.py +++ b/addon_imps/storage/owncloud.py @@ -63,6 +63,7 @@ async def get_external_account_id(self, auth_result_extras: dict[str, str]) -> s response_xml = await response.text_content() return self._parse_displayname(response_xml) + @property def _fallback_username(self) -> str | None: return "default-username" diff --git a/addon_service/common/waterbutler_compat.py b/addon_service/common/waterbutler_compat.py index cb2e8988..f6d59ab1 100644 --- a/addon_service/common/waterbutler_compat.py +++ b/addon_service/common/waterbutler_compat.py @@ -22,14 +22,27 @@ class JSONAPIMeta: credentials = serializers.SerializerMethodField("_credentials_for_waterbutler") config = serializers.SerializerMethodField("_config_for_waterbutler") + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self._wb_config_cache = {} + + def _get_wb_config(self, configured_storage_addon): + cache_key = configured_storage_addon.id + if cache_key in self._wb_config_cache: + return self._wb_config_cache[cache_key] + else: + imp = get_storage_addon_instance__blocking( + configured_storage_addon.imp_cls, + configured_storage_addon.base_account, + configured_storage_addon.config, + ) + wb_config = async_to_sync(imp.build_wb_config)() + self._wb_config_cache[cache_key] = wb_config + return wb_config + def _credentials_for_waterbutler(self, configured_storage_addon): _creds_data = configured_storage_addon.credentials - imp = get_storage_addon_instance__blocking( - configured_storage_addon.imp_cls, - configured_storage_addon.base_account, - configured_storage_addon.config, - ) - wb_config = async_to_sync(imp.build_wb_config)() + wb_config = self._get_wb_config(configured_storage_addon) match type(_creds_data): case credentials.AccessTokenCredentials: @@ -50,10 +63,5 @@ def _credentials_for_waterbutler(self, configured_storage_addon): raise ValueError(f"unknown credentials type: {_creds_data}") def _config_for_waterbutler(self, configured_storage_addon: ConfiguredStorageAddon): - imp = get_storage_addon_instance__blocking( - configured_storage_addon.imp_cls, - configured_storage_addon.base_account, - configured_storage_addon.config, - ) - wb_config = async_to_sync(imp.build_wb_config)() + wb_config = self._get_wb_config(configured_storage_addon) return wb_config