[recipes: 3/4] Do less work when recipes change
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [recipes: 3/4] Do less work when recipes change
- Date: Sat, 11 Feb 2017 20:04:12 +0000 (UTC)
commit aaca35e8db4451586e0416a947b5d9ffd252b1d7
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Feb 11 14:41:54 2017 -0500
Do less work when recipes change
We were just rebuilding all the pages, all the time, regardless
whether they are currently shown or not. This was very noticable
when using the serves spin on the shopping page - it took a
long time for the page to refresh, several hundred milliseconds.
With this change, we update in ~20.
src/gr-cuisine-page.c | 4 ++--
src/gr-cuisines-page.c | 12 +++++++++---
src/gr-cuisines-page.h | 3 ++-
src/gr-details-page.c | 3 +++
src/gr-list-page.c | 14 ++++++++++----
src/gr-recipes-page.c | 13 ++++++++++---
src/gr-recipes-page.h | 1 +
src/gr-search-page.c | 4 ++--
src/gr-shopping-page.c | 7 ++++++-
src/gr-window.c | 2 ++
10 files changed, 47 insertions(+), 16 deletions(-)
---
diff --git a/src/gr-cuisine-page.c b/src/gr-cuisine-page.c
index 664ce9b..d49e208 100644
--- a/src/gr-cuisine-page.c
+++ b/src/gr-cuisine-page.c
@@ -299,7 +299,8 @@ gr_cuisine_page_set_cuisine (GrCuisinePage *self,
static void
cuisine_page_reload (GrCuisinePage *page)
{
- gr_cuisine_page_set_cuisine (page, page->cuisine);
+ if (gtk_widget_is_drawable (GTK_WIDGET (page)))
+ gr_cuisine_page_set_cuisine (page, page->cuisine);
}
static void
@@ -309,7 +310,6 @@ connect_store_signals (GrCuisinePage *page)
store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
- /* FIXME: inefficient */
g_signal_connect_swapped (store, "recipe-added", G_CALLBACK (cuisine_page_reload), page);
g_signal_connect_swapped (store, "recipe-removed", G_CALLBACK (cuisine_page_reload), page);
g_signal_connect_swapped (store, "recipe-changed", G_CALLBACK (cuisine_page_reload), page);
diff --git a/src/gr-cuisines-page.c b/src/gr-cuisines-page.c
index 7f820de..d184052 100644
--- a/src/gr-cuisines-page.c
+++ b/src/gr-cuisines-page.c
@@ -227,21 +227,27 @@ gr_cuisines_page_new (void)
return GTK_WIDGET (page);
}
-static void
-cuisines_page_reload (GrCuisinesPage *page)
+void
+gr_cuisines_page_refresh (GrCuisinesPage *page)
{
populate_cuisines (page);
populate_seasonal (page);
}
static void
+cuisines_page_reload (GrCuisinesPage *page)
+{
+ if (gtk_widget_is_drawable (GTK_WIDGET (page)))
+ gr_cuisines_page_refresh (page);
+}
+
+static void
connect_store_signals (GrCuisinesPage *page)
{
GrRecipeStore *store;
store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
- /* FIXME: inefficient */
g_signal_connect_swapped (store, "recipe-added", G_CALLBACK (cuisines_page_reload), page);
g_signal_connect_swapped (store, "recipe-removed", G_CALLBACK (cuisines_page_reload), page);
g_signal_connect_swapped (store, "recipe-changed", G_CALLBACK (cuisines_page_reload), page);
diff --git a/src/gr-cuisines-page.h b/src/gr-cuisines-page.h
index 9cc72e6..7aed577 100644
--- a/src/gr-cuisines-page.h
+++ b/src/gr-cuisines-page.h
@@ -28,8 +28,9 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GrCuisinesPage, gr_cuisines_page, GR, CUISINES_PAGE, GtkBox)
-GtkWidget *gr_cuisines_page_new (void);
+GtkWidget *gr_cuisines_page_new (void);
+void gr_cuisines_page_refresh (GrCuisinesPage *page);
void gr_cuisines_page_unexpand (GrCuisinesPage *page);
diff --git a/src/gr-details-page.c b/src/gr-details-page.c
index 687ed41..b39e6e3 100644
--- a/src/gr-details-page.c
+++ b/src/gr-details-page.c
@@ -718,6 +718,9 @@ details_page_reload (GrDetailsPage *page,
if (recipe == NULL || page->recipe == NULL)
return;
+ if (!gtk_widget_is_drawable (GTK_WIDGET (page)))
+ return;
+
name = gr_recipe_get_id (page->recipe);
new_name = gr_recipe_get_id (recipe);
if (g_strcmp0 (name, new_name) == 0)
diff --git a/src/gr-list-page.c b/src/gr-list-page.c
index 1332ba5..fc6fbb4 100644
--- a/src/gr-list-page.c
+++ b/src/gr-list-page.c
@@ -443,16 +443,22 @@ gr_list_page_repopulate (GrListPage *page)
}
static void
+repopulate (GrListPage *page)
+{
+ if (gtk_widget_is_drawable (GTK_WIDGET (page)))
+ gr_list_page_repopulate (page);
+}
+
+static void
connect_store_signals (GrListPage *page)
{
GrRecipeStore *store;
store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
- /* FIXME: inefficient */
- g_signal_connect_swapped (store, "recipe-added", G_CALLBACK (gr_list_page_repopulate), page);
- g_signal_connect_swapped (store, "recipe-removed", G_CALLBACK (gr_list_page_repopulate), page);
- g_signal_connect_swapped (store, "recipe-changed", G_CALLBACK (gr_list_page_repopulate), page);
+ g_signal_connect_swapped (store, "recipe-added", G_CALLBACK (repopulate), page);
+ g_signal_connect_swapped (store, "recipe-removed", G_CALLBACK (repopulate), page);
+ g_signal_connect_swapped (store, "recipe-changed", G_CALLBACK (repopulate), page);
}
void
diff --git a/src/gr-recipes-page.c b/src/gr-recipes-page.c
index 27fca34..0330988 100644
--- a/src/gr-recipes-page.c
+++ b/src/gr-recipes-page.c
@@ -359,8 +359,8 @@ populate_recipes_from_store (GrRecipesPage *self)
update_shopping_time (self);
}
-static void
-repopulate_recipes (GrRecipesPage *self)
+void
+gr_recipes_page_refresh (GrRecipesPage *self)
{
populate_recipes_from_store (self);
populate_diets_from_store (self);
@@ -368,6 +368,14 @@ repopulate_recipes (GrRecipesPage *self)
gr_chef_tile_recreate_css ();
}
+
+static void
+repopulate_recipes (GrRecipesPage *self)
+{
+ if (gtk_widget_is_drawable (GTK_WIDGET (self)))
+ gr_recipes_page_refresh (self);
+}
+
static void
populate_chefs_from_store (GrRecipesPage *self)
{
@@ -421,7 +429,6 @@ connect_store_signals (GrRecipesPage *page)
store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
- /* FIXME: inefficient */
g_signal_connect_swapped (store, "recipe-added", G_CALLBACK (repopulate_recipes), page);
g_signal_connect_swapped (store, "recipe-removed", G_CALLBACK (repopulate_recipes), page);
g_signal_connect_swapped (store, "recipe-changed", G_CALLBACK (repopulate_recipes), page);
diff --git a/src/gr-recipes-page.h b/src/gr-recipes-page.h
index 3a29b01..05ec3ba 100644
--- a/src/gr-recipes-page.h
+++ b/src/gr-recipes-page.h
@@ -30,6 +30,7 @@ G_DECLARE_FINAL_TYPE (GrRecipesPage, gr_recipes_page, GR, RECIPES_PAGE, GtkBox)
GtkWidget *gr_recipes_page_new (void);
+void gr_recipes_page_refresh (GrRecipesPage *page);
void gr_recipes_page_unexpand (GrRecipesPage *page);
G_END_DECLS
diff --git a/src/gr-search-page.c b/src/gr-search-page.c
index 3d1e51e..4e5f23f 100644
--- a/src/gr-search-page.c
+++ b/src/gr-search-page.c
@@ -192,7 +192,8 @@ gr_search_page_update_search (GrSearchPage *page,
static void
search_page_reload (GrSearchPage *page)
{
- gr_search_page_update_search (page, gr_recipe_search_get_terms (page->search));
+ if (gtk_widget_is_drawable (GTK_WIDGET (page)))
+ gr_search_page_update_search (page, gr_recipe_search_get_terms (page->search));
}
static void
@@ -202,7 +203,6 @@ connect_store_signals (GrSearchPage *page)
store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
- /* FIXME: inefficient */
g_signal_connect_swapped (store, "recipe-added", G_CALLBACK (search_page_reload), page);
g_signal_connect_swapped (store, "recipe-removed", G_CALLBACK (search_page_reload), page);
g_signal_connect_swapped (store, "recipe-changed", G_CALLBACK (search_page_reload), page);
diff --git a/src/gr-shopping-page.c b/src/gr-shopping-page.c
index 2e49578..b5bd44d 100644
--- a/src/gr-shopping-page.c
+++ b/src/gr-shopping-page.c
@@ -849,6 +849,9 @@ recipe_added (GrShoppingPage *page,
GList *children, *l;
int serves;
+ if (!gtk_widget_is_drawable (GTK_WIDGET (page)))
+ return;
+
store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
serves = gr_recipe_store_get_shopping_serves (store, recipe);
@@ -883,6 +886,9 @@ recipe_changed (GrShoppingPage *page,
{
GrRecipeStore *store;
+ if (!gtk_widget_is_drawable (GTK_WIDGET (page)))
+ return;
+
store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
if (gr_recipe_store_is_in_shopping (store, recipe))
@@ -898,7 +904,6 @@ connect_store_signals (GrShoppingPage *page)
store = gr_app_get_recipe_store (GR_APP (g_application_get_default ()));
- /* FIXME: inefficient */
g_signal_connect_swapped (store, "recipe-removed", G_CALLBACK (recipe_removed), page);
g_signal_connect_swapped (store, "recipe-changed", G_CALLBACK (recipe_changed), page);
}
diff --git a/src/gr-window.c b/src/gr-window.c
index acd774f..00438b5 100644
--- a/src/gr-window.c
+++ b/src/gr-window.c
@@ -268,10 +268,12 @@ visible_page_changed (GrWindow *window)
}
if (strcmp (visible, "recipes") == 0) {
+ gr_recipes_page_refresh (GR_RECIPES_PAGE (window->recipes_page));
gr_recipes_page_unexpand (GR_RECIPES_PAGE (window->recipes_page));
}
if (strcmp (visible, "cuisines") == 0) {
+ gr_cuisines_page_refresh (GR_CUISINES_PAGE (window->cuisines_page));
gr_cuisines_page_unexpand (GR_CUISINES_PAGE (window->cuisines_page));
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]