#pragma once #include #include #include #include #include namespace DB { class AccessControl; struct SettingsProfile; using SettingsProfilePtr = std::shared_ptr; struct SettingsProfilesInfo; /// Reads and caches all the settings profiles. class SettingsProfilesCache { public: explicit SettingsProfilesCache(const AccessControl & access_control_); ~SettingsProfilesCache(); void setDefaultProfileName(const String & default_profile_name); std::shared_ptr getEnabledSettings( const UUID & user_id, const SettingsProfileElements & settings_from_user_, const boost::container::flat_set & enabled_roles, const SettingsProfileElements & settings_from_enabled_roles_); std::shared_ptr getSettingsProfileInfo(const UUID & profile_id); private: void ensureAllProfilesRead(); void profileAddedOrChanged(const UUID & profile_id, const SettingsProfilePtr & new_profile); void profileRemoved(const UUID & profile_id); void mergeSettingsAndConstraints(); void mergeSettingsAndConstraintsFor(EnabledSettings & enabled) const; void substituteProfiles(SettingsProfileElements & elements, std::vector & profiles, std::vector & substituted_profiles, std::unordered_map & names_of_substituted_profiles) const; const AccessControl & access_control; std::unordered_map all_profiles; std::unordered_map profiles_by_name; bool all_profiles_read = false; scope_guard subscription; std::map> enabled_settings; std::optional default_profile_id; Poco::LRUCache> profile_infos_cache; mutable std::mutex mutex; }; }