From 0228e9afe327ee4990dc86195168f5b5bf4aa49a Mon Sep 17 00:00:00 2001 From: "hanno@schwalm-bremen.de" Date: Sat, 27 Jan 2024 08:11:46 +0100 Subject: [PATCH] Autosave history fixes If autosaving history we keep track of last savetime immediately. Also do improved logs for times spent on writing history and writing the xmp file and always do a log when autosaving has been disabled. --- src/develop/develop.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/develop/develop.c b/src/develop/develop.c index 5827dc6d1058..8e7a90128e13 100644 --- a/src/develop/develop.c +++ b/src/develop/develop.c @@ -714,34 +714,40 @@ static void _dev_auto_save(dt_develop_t *dev) static double last = 0.0; const double user_delay = (double)dt_conf_get_int("autosave_interval"); - const double now = dt_get_wtime(); - const dt_imgid_t imgid = dev->image_storage.id; /* We can only autosave database & xmp while we have a valid image id and we are not currently loading or changing it in main darkroom */ const gboolean saving = (user_delay >= 1.0) - && ((now - last) > user_delay) + && ((dt_get_wtime() - last) > user_delay) && !dev->full.pipe->loading && dev->requested_id == imgid && dt_is_valid_imgid(imgid); if(saving) { + // avoid saving for fast repeated calls + last = dt_get_wtime(); // Ok, lets save status for image dt_dev_write_history(dev); + + // check for slow drives + const double start = dt_get_wtime(); dt_image_write_sidecar_file(imgid); - last = now; + const double after = dt_get_wtime(); - const double spent = dt_get_wtime() - now; - dt_print(DT_DEBUG_DEV, "autosave history took %fsec\n", spent); + dt_print(DT_DEBUG_DEV, "autosave history took %.3fs (hist) %.3fs (drive)\n", + start - last, after - start); // if writing to database and the xmp took too long we disable // autosaving mode for this session - if(spent > 0.5) + if((after - last) > 0.5) { dev->autosaving = FALSE; + dt_print(DT_DEBUG_ALL, "autosave history disabled, took %.3fs (hist) %.3fs (drive)\n", + start - last, after - start); + dt_control_log(_("autosaving history has been disabled" " for this session because of a slow drive used")); }