#pragma once #include #include #include #include #include #include namespace DB { class AccessControlManager; struct SettingsProfile; using SettingsProfilePtr = std::shared_ptr; class SettingsProfileElements; class EnabledSettings; /// Reads and caches all the settings profiles. class SettingsProfilesCache { public: SettingsProfilesCache(const AccessControlManager & manager_); ~SettingsProfilesCache(); void setDefaultProfileName(const String & default_profile_name); std::shared_ptr getEnabledSettings( const UUID & user_id, const SettingsProfileElements & settings_from_user_, const std::vector & enabled_roles, const SettingsProfileElements & settings_from_enabled_roles_); std::shared_ptr getProfileSettings(const String & profile_name); 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) const; const AccessControlManager & manager; std::unordered_map all_profiles; std::unordered_map profiles_by_name; bool all_profiles_read = false; ext::scope_guard subscription; std::map> enabled_settings; std::optional default_profile_id; std::unordered_map> settings_for_profiles; mutable std::mutex mutex; }; }