[gnome-builder] libide/projects: add delay before reloading recent projects
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide/projects: add delay before reloading recent projects
- Date: Thu, 22 Sep 2022 05:20:30 +0000 (UTC)
commit 973782dda3e401a539ff94a50e3d2e2849320f88
Author: Christian Hergert <chergert redhat com>
Date: Wed Sep 21 22:20:24 2022 -0700
libide/projects: add delay before reloading recent projects
src/libide/projects/ide-recent-projects.c | 44 ++++++++++++++++++-------------
1 file changed, 26 insertions(+), 18 deletions(-)
---
diff --git a/src/libide/projects/ide-recent-projects.c b/src/libide/projects/ide-recent-projects.c
index 739acc012..16b4012c9 100644
--- a/src/libide/projects/ide-recent-projects.c
+++ b/src/libide/projects/ide-recent-projects.c
@@ -30,6 +30,8 @@
#include "ide-project-info-private.h"
#include "ide-recent-projects.h"
+#define INVALIDATE_DELAY_SECONDS 5
+
struct _IdeRecentProjects
{
GObject parent_instance;
@@ -440,10 +442,24 @@ static gboolean
ide_recent_projects_reload_in_idle_cb (gpointer user_data)
{
IdeRecentProjects *self = user_data;
+ g_autoptr(GSequence) sequence = NULL;
+ g_autoptr(GHashTable) hashtable = NULL;
+ guint n_items;
g_assert (IDE_IS_RECENT_PROJECTS (self));
+ sequence = g_steal_pointer (&self->projects);
+ self->projects = g_sequence_new (g_object_unref);
+
+ hashtable = g_steal_pointer (&self->recent_uris);
+ self->recent_uris = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+
+ /* Notify of removals, so we can re-add new items next */
+ n_items = g_sequence_get_length (sequence);
+ g_list_model_items_changed (G_LIST_MODEL (self), 0, n_items, 0);
+
ide_recent_projects_load_recent (self);
+
self->reloading = FALSE;
return G_SOURCE_REMOVE;
@@ -452,9 +468,6 @@ ide_recent_projects_reload_in_idle_cb (gpointer user_data)
void
ide_recent_projects_invalidate (IdeRecentProjects *self)
{
- g_autoptr(GSequence) sequence = NULL;
- g_autoptr(GHashTable) hashtable = NULL;
- guint n_items;
g_return_if_fail (IDE_IS_MAIN_THREAD ());
g_return_if_fail (IDE_IS_RECENT_PROJECTS (self));
@@ -462,24 +475,19 @@ ide_recent_projects_invalidate (IdeRecentProjects *self)
if (self->reloading)
return;
- sequence = g_steal_pointer (&self->projects);
- self->projects = g_sequence_new (g_object_unref);
-
- hashtable = g_steal_pointer (&self->recent_uris);
- self->recent_uris = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
-
- /* Notify of removals, so we can re-add new items next */
- n_items = g_sequence_get_length (sequence);
- g_list_model_items_changed (G_LIST_MODEL (self), 0, n_items, 0);
-
- /* Reload from IDLE so higher priority operations can finish
+ /* Reload from timeout so higher priority operations can finish
* before yielding to main loop (since this is all currently
* done synchronously). In practice the file will still be hot
* in the page cache, so relatively fast regardless.
+ *
+ * The main reason for timeout over idle is to increase the chance
+ * that we are not going to mess with the GtkListView of projects
+ * by causing items-changed to occur.
*/
self->reloading = TRUE;
- g_idle_add_full (G_PRIORITY_LOW + 1000,
- ide_recent_projects_reload_in_idle_cb,
- g_object_ref (self),
- g_object_unref);
+ g_timeout_add_seconds_full (G_PRIORITY_LOW + 1000,
+ INVALIDATE_DELAY_SECONDS,
+ ide_recent_projects_reload_in_idle_cb,
+ g_object_ref (self),
+ g_object_unref);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]