From 7823e8120d75e366246279c888865b7d6ffeb679 Mon Sep 17 00:00:00 2001 From: Corey Berla Date: Tue, 6 Feb 2024 11:24:27 -0800 Subject: [PATCH 1/3] filechooserwidget: Load recent files in bulk We add recent files one at a time which is incredibly wasteful. This is most obvious when the action is SAVE or OPEN_FOLDER because we aren't limiting the number of recent files (as we are with OPEN), so for me it took about 5 seconds to open a file dialog with OPEN_FOLDER since the default location is recents. --- gtk/gtkfilechooserwidget.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index b2bce9f138..fd27b55631 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -5924,6 +5924,7 @@ recent_start_loading (GtkFileChooserWidget *impl) { const int limit = DEFAULT_RECENT_FILES_LIMIT; const char *app_name = g_get_application_name (); + GList *files = NULL; GList *l; int n; @@ -5941,31 +5942,30 @@ recent_start_loading (GtkFileChooserWidget *impl) !gtk_recent_info_has_application (info, app_name)) continue; - file = g_file_new_for_uri (gtk_recent_info_get_uri (info)); - _gtk_file_system_model_add_and_query_file (impl->recent_model, - file, - MODEL_ATTRIBUTES); - g_object_unref (file); + files = g_list_prepend (files, file); n++; if (limit != -1 && n >= limit) break; } + files = g_list_reverse (files); + _gtk_file_system_model_add_and_query_files (impl->recent_model, + files, + MODEL_ATTRIBUTES); + g_list_free_full (files, g_object_unref); + g_set_object (&impl->model_for_search, impl->recent_model); } else { GList *folders; - GList *l; folders = _gtk_file_chooser_extract_recent_folders (items); - - for (l = folders; l; l = l->next) - _gtk_file_system_model_add_and_query_file (impl->recent_model, - G_FILE (l->data), - MODEL_ATTRIBUTES); + _gtk_file_system_model_add_and_query_files (impl->recent_model, + folders, + MODEL_ATTRIBUTES); g_list_free_full (folders, g_object_unref); } From 8f3d85007b6909fafacd55025af075eb807cbbde Mon Sep 17 00:00:00 2001 From: Corey Berla Date: Tue, 6 Feb 2024 11:27:08 -0800 Subject: [PATCH 2/3] filechooserwidget: Limit recent folders to default limit --- gtk/gtkfilechooserwidget.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index fd27b55631..ce34f9e93d 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -639,6 +639,7 @@ _gtk_file_chooser_extract_recent_folders (GList *infos) GList *l; GList *result; GHashTable *folders; + guint counter = 0; result = NULL; @@ -651,6 +652,9 @@ _gtk_file_chooser_extract_recent_folders (GList *infos) GFile *dir; GFile *file; + if (counter >= DEFAULT_RECENT_FILES_LIMIT) + break; + if (!gtk_recent_info_is_local (info)) continue; @@ -674,6 +678,7 @@ _gtk_file_chooser_extract_recent_folders (GList *infos) { g_hash_table_insert (folders, dir, (gpointer) 1); result = g_list_prepend (result, g_object_ref (dir)); + counter++; } g_object_unref (dir); From 99dd6c579d463e36c6d2745f71d5510dde9d2f6a Mon Sep 17 00:00:00 2001 From: Corey Berla Date: Tue, 6 Feb 2024 11:31:05 -0800 Subject: [PATCH 3/3] filechooserwidget: Reuse timzezone It's wasteful to call _local api's multiple times. --- gtk/gtkfilechooserwidget.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index ce34f9e93d..985c9b980c 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -3723,21 +3723,25 @@ my_g_format_date_for_display (GtkFileChooserWidget *impl, { GDateTime *now, *time; GDateTime *now_date, *date; + GTimeZone *tz; const char *format; char *date_str; int days_ago; + tz = g_time_zone_new_local (); time = g_date_time_new_from_unix_local (secs); - date = g_date_time_new_local (g_date_time_get_year (time), - g_date_time_get_month (time), - g_date_time_get_day_of_month (time), - 0, 0, 0); + date = g_date_time_new (tz, + g_date_time_get_year (time), + g_date_time_get_month (time), + g_date_time_get_day_of_month (time), + 0, 0, 0); - now = g_date_time_new_now_local (); - now_date = g_date_time_new_local (g_date_time_get_year (now), - g_date_time_get_month (now), - g_date_time_get_day_of_month (now), - 0, 0, 0); + now = g_date_time_new_now (tz); + now_date = g_date_time_new (tz, + g_date_time_get_year (now), + g_date_time_get_month (now), + g_date_time_get_day_of_month (now), + 0, 0, 0); days_ago = g_date_time_difference (now_date, date) / G_TIME_SPAN_DAY; if (days_ago < 1)