Skip to content

Commit

Permalink
splashscreen: increase update freq at start of sidecar crawl (#17807)
Browse files Browse the repository at this point in the history
* increase update freq at start of sidecar crawl
  • Loading branch information
ralfbrown authored Nov 12, 2024
1 parent 656426a commit 1af90a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
20 changes: 14 additions & 6 deletions src/control/crawler.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ static void _set_modification_time(char *filename,
if(info) g_clear_object(&info);
}

// pregress update intervals in seconds
#define FAST_UPDATE 0.2
#define SLOW_UPDATE 1.0

GList *dt_control_crawler_run(void)
{
sqlite3_stmt *stmt, *inner_stmt;
Expand Down Expand Up @@ -140,8 +144,11 @@ GList *dt_control_crawler_run(void)
dt_database_start_transaction(darktable.db);

int image_count = 0;
double start_time = dt_get_wtime();
double last_time = start_time - 0.99; // wait 10ms before first update to ensure visibility
const double start_time = dt_get_wtime();
// set the "previous update" time to 10ms after a notional previous
// update to ensure visibility of the first update (which might not
// appear when done with zero delay) while minimizing the delay
double last_time = start_time - (FAST_UPDATE-0.01);

while(sqlite3_step(stmt) == SQLITE_ROW)
{
Expand All @@ -150,12 +157,13 @@ GList *dt_control_crawler_run(void)
const int version = sqlite3_column_int(stmt, 2);
const gchar *image_path = (char *)sqlite3_column_text(stmt, 3);
int flags = sqlite3_column_int(stmt, 4);
++image_count;

// update the progress message once per second
double fraction = (++image_count) / (double)total_images;
double curr_time = dt_get_wtime();
if(curr_time >= last_time + 1.0)
// update the progress message - five times per second for first four seconds, then once per second
const double curr_time = dt_get_wtime();
if(curr_time >= last_time + ((curr_time - start_time > 4.0) ? SLOW_UPDATE : FAST_UPDATE))
{
const double fraction = image_count / (double)total_images;
darktable_splash_screen_set_progress_percent(_("checking for updated sidecar files (%d%%)"),
fraction,
curr_time - start_time);
Expand Down
4 changes: 2 additions & 2 deletions src/gui/splash.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,10 @@ void darktable_splash_screen_set_progress_percent(const char *msg,
gtk_label_set_text(GTK_LABEL(progress_text), text);
g_free(text);

if(elapsed >= 2.0 && fraction > 0.02)
if(elapsed >= 2.0 || fraction > 0.01)
{
const double total = elapsed / fraction;
const double remain = total - elapsed;
const double remain = (total - elapsed) + 0.5; // round to full seconds rather than truncating
const int minutes = remain / 60;
const int seconds = remain - (60 * minutes);
char *rem_text = g_strdup_printf(" %4d:%02d", minutes, seconds);
Expand Down

0 comments on commit 1af90a3

Please sign in to comment.