@@ -79,42 +79,36 @@ bool properties_t::get_bool(std::string const &property,
7979void properties_t::set_string (std::string property, std::string value,
8080 bool update_database)
8181{
82- m_properties.insert_or_assign (std::move (property), std::move (value));
83- if (update_database) {
84- update (property);
82+ auto const r =
83+ m_properties.insert_or_assign (std::move (property), std::move (value));
84+
85+ if (!update_database) {
86+ return ;
8587 }
88+
89+ auto const &inserted = *(r.first );
90+ log_debug (" Storing {}='{}'" , inserted.first , inserted.second );
91+
92+ pg_conn_t const db_connection{m_conninfo};
93+ db_connection.exec (
94+ " PREPARE set_property(text, text) AS"
95+ " INSERT INTO {} (property, value) VALUES ($1, $2)"
96+ " ON CONFLICT (property) DO UPDATE SET value = EXCLUDED.value" ,
97+ table_name ());
98+ db_connection.exec_prepared (" set_property" , inserted.first ,
99+ inserted.second );
86100}
87101
88102void properties_t::set_int (std::string property, int64_t value,
89103 bool update_database)
90104{
91- m_properties.insert_or_assign (std::move (property), std::to_string (value));
92- if (update_database) {
93- update (property);
94- }
105+ set_string (std::move (property), std::to_string (value), update_database);
95106}
96107
97108void properties_t::set_bool (std::string property, bool value,
98109 bool update_database)
99110{
100- m_properties.insert_or_assign (std::move (property),
101- value ? " true" : " false" );
102- if (update_database) {
103- update (property);
104- }
105- }
106-
107- void properties_t::update (std::string const &property) const
108- {
109- pg_conn_t const db_connection{m_conninfo};
110-
111- db_connection.exec (" PREPARE set_property(text, text) AS"
112- " UPDATE {} SET value = $2 WHERE property = $1" ,
113- table_name ());
114-
115- auto const value = m_properties.at (property);
116- log_debug (" Storing {}='{}'" , property, value);
117- db_connection.exec_prepared (" set_property" , property, value);
111+ set_string (std::move (property), value ? " true" : " false" , update_database);
118112}
119113
120114void properties_t::store ()
0 commit comments