From 6ab2fadfdba6578fd7742d87a386df5e1838f3f2 Mon Sep 17 00:00:00 2001 From: Teus Benschop Date: Sat, 11 May 2024 18:46:33 +0200 Subject: [PATCH] Setting in user configuration whether to have spell check enable The setting is on by default. https://github.com/bibledit/cloud/issues/937 --- database/config/user.cpp | 36 +++++++++++++++++++++++++----------- database/config/user.h | 2 ++ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/database/config/user.cpp b/database/config/user.cpp index e9a5a2cd9..6e3d4ba65 100644 --- a/database/config/user.cpp +++ b/database/config/user.cpp @@ -69,14 +69,14 @@ std::string Database_Config_User::mapkey (std::string user, const char * key) std::string Database_Config_User::getValue (const char * key, const char * default_value) { - std::string user = m_webserver_request.session_logic ()->currentUser (); + const std::string user = m_webserver_request.session_logic ()->currentUser (); return getValueForUser (user, key, default_value); } bool Database_Config_User::getBValue (const char * key, bool default_value) { - std::string value = getValue (key, filter::strings::convert_to_string (default_value).c_str()); + const std::string value = getValue (key, filter::strings::convert_to_string (default_value).c_str()); return filter::strings::convert_to_bool (value); } @@ -90,18 +90,21 @@ int Database_Config_User::getIValue (const char * key, int default_value) std::string Database_Config_User::getValueForUser (std::string user, const char * key, const char * default_value) { - // Check the memory cache. - std::string cachekey = mapkey (user, key); + // Check the memory cache. If it is there, read it from the memory cache. + const std::string cachekey = mapkey (user, key); if (database_config_user_cache.count (cachekey)) { - return database_config_user_cache [cachekey]; + return database_config_user_cache.at (cachekey); } // Read from file. std::string value; - std::string filename = file (user, key); - if (file_or_dir_exists (filename)) value = filter_url_file_get_contents (filename); - else value = default_value; - // Cache it. - database_config_user_cache [cachekey] = value; + const std::string filename = file (user, key); + if (file_or_dir_exists (filename)) + value = filter_url_file_get_contents (filename); + else + value = default_value; + // Cache it, so next time getting when this value, + // it does not read it from disk but from memory cache, which will be faster. + database_config_user_cache.insert_or_assign (cachekey, value); // Done. return value; } @@ -123,7 +126,7 @@ int Database_Config_User::getIValueForUser (std::string user, const char * key, void Database_Config_User::setValue (const char * key, std::string value) { - std::string user = m_webserver_request.session_logic ()->currentUser (); + const std::string user = m_webserver_request.session_logic ()->currentUser (); setValueForUser (user, key, value); } @@ -1496,3 +1499,14 @@ void Database_Config_User::setChangeNotificationsBibles (const std::vector getChangeNotificationsBibles (); std::vector getChangeNotificationsBiblesForUser (const std::string & user); void setChangeNotificationsBibles (const std::vector & values); + bool get_enable_spell_check (); + void set_enable_spell_check (bool value); private: Webserver_Request& m_webserver_request; std::string file (std::string user);