craigk5n / webcalendar

WebCalendar is a PHP application used to maintain a calendar for a single user or an intranet group of users. It can also be configured as an event calendar.
http://www.k5n.us/webcalendar.php
GNU General Public License v2.0
149 stars 71 forks source link

Only save new values for system settings page #336

Open elacour opened 1 year ago

elacour commented 1 year ago

Updating a system setting is very slow. Looking at the DB, seems that every configuration value leads to a DELETE followed by an INSERT, the modified and not modified ones.

Only updated settings should be updated in database.

craigk5n commented 10 months ago

Ideally, yes. However, to know if a setting exists (keep in mind that another user could be modifying at the same time), you need to query first and then update. Another option is to use the INSERT ... ON DUPLICATE KEY UPDATE that MySQL supports. However, SQLite uses something different (INSERT OR REPLACE) as does PostgreSQL. A final option would be do always do UPDATE and catch Exceptions where an INSERT could happen...

In any event, I've got a 3 year-old Intel i5 that saves all the settings in less than a second. And most users don't actually save settings that many times. So, I'm happy to take code contributions. But, this seems like a lot of trouble to go through for a very small performance boost.