[tracker/tracker-0.6] Code clean ups and improvements for stats speed up changes



commit 7010a7c297274b8e1a3e9c433e8ea72ae99fa2d9
Author: Martyn Russell <martyn imendio com>
Date:   Wed Jun 17 13:19:45 2009 +0100

    Code clean ups and improvements for stats speed up changes

 src/libtracker-common/tracker-ontology.c |   23 +++++++-------
 src/libtracker-common/tracker-ontology.h |    2 +-
 src/trackerd/tracker-daemon.c            |   48 +++++++++++++----------------
 3 files changed, 34 insertions(+), 39 deletions(-)
---
diff --git a/src/libtracker-common/tracker-ontology.c b/src/libtracker-common/tracker-ontology.c
index 10d68da..1e876b3 100644
--- a/src/libtracker-common/tracker-ontology.c
+++ b/src/libtracker-common/tracker-ontology.c
@@ -50,7 +50,7 @@ static GHashTable *service_names;
 static GHashTable *mimes_to_service_ids;
 
 /* List of ServiceMimePrefixes */
-static GSList	  *service_mime_prefixes = NULL;
+static GSList	  *service_mime_prefixes;
 
 /* Field descriptions */
 static GHashTable *field_names;
@@ -61,8 +61,8 @@ static gpointer    field_type_enum_class;
 /* Category - subcategory ids cache */
 static GHashTable *subcategories_cache;
 
-/* List of top services in the hierarchy */ 
-static GSList *top_services = NULL;
+/* List of parent services in the hierarchy */ 
+static GSList     *parent_services;
 
 static void
 ontology_mime_prefix_foreach (gpointer data,
@@ -202,9 +202,9 @@ tracker_ontology_shutdown (void)
 		service_mime_prefixes = NULL;
 	}
 
-	if (top_services) {
-		g_slist_free (top_services);
-		top_services = NULL;
+	if (parent_services) {
+		g_slist_free (parent_services);
+		parent_services = NULL;
 	}
 
 	g_type_class_unref (field_type_enum_class);
@@ -237,8 +237,8 @@ tracker_ontology_service_add (TrackerService *service,
 			     g_object_ref (service));
 
 	if (tracker_service_get_parent (service) == NULL ||
-	    !g_strcmp0 (tracker_service_get_parent (service), " ")) {
-		top_services = g_slist_prepend (top_services, service);
+	    g_strcmp0 (tracker_service_get_parent (service), " ") == 0) {
+		parent_services = g_slist_prepend (parent_services, service);
 	}
 
 	for (l = mimes; l && l->data; l = l->next) {
@@ -253,7 +253,7 @@ tracker_ontology_service_add (TrackerService *service,
 		service_mime_prefix->service = id;
 
 		service_mime_prefixes = g_slist_prepend (service_mime_prefixes,
-						       service_mime_prefix);
+							 service_mime_prefix);
 	}
 }
 
@@ -528,11 +528,10 @@ tracker_ontology_get_subcategory_ids (const gchar *service_str)
 	return subcategories;
 }
 
-
 GSList *        
-tracker_ontology_get_top_services (void)
+tracker_ontology_get_parent_services (void)
 {
-	return top_services;
+	return parent_services;
 }
 
 /*
diff --git a/src/libtracker-common/tracker-ontology.h b/src/libtracker-common/tracker-ontology.h
index 59d6063..ea29d1c 100644
--- a/src/libtracker-common/tracker-ontology.h
+++ b/src/libtracker-common/tracker-ontology.h
@@ -53,7 +53,7 @@ gint		tracker_ontology_get_service_parent_id_by_id	(gint		 id);
 GSList *	tracker_ontology_get_service_names_registered	(void);
 GSList *	tracker_ontology_get_field_names_registered	(const gchar	*service_str);
 GArray *        tracker_ontology_get_subcategory_ids            (const gchar    *service_str);
-GSList *        tracker_ontology_get_top_services               (void);
+GSList *        tracker_ontology_get_parent_services            (void);
 
 /* Service data */
 gboolean	tracker_ontology_service_is_valid		(const gchar	*service_str);
diff --git a/src/trackerd/tracker-daemon.c b/src/trackerd/tracker-daemon.c
index 03d7557..c0b6b79 100644
--- a/src/trackerd/tracker-daemon.c
+++ b/src/trackerd/tracker-daemon.c
@@ -420,6 +420,7 @@ stats_cache_get_latest (void)
 	GHashTable         *services;
 	GHashTable         *values;
 	GHashTableIter      iter;
+	GSList             *parent_services, *l;
 	gpointer            key, value;
 	guint               i;
 	const gchar        *services_to_fetch[3] = { 
@@ -475,46 +476,41 @@ stats_cache_get_latest (void)
 
 	/*
 	 * For each of the top services, add the items of their subservices 
-	 *  (calculated in the previous GetStats)
+	 * (calculated in the previous GetStats)
 	 */
-	GSList *top_services = NULL;
-	GSList *tops = NULL;
+	parent_services = tracker_ontology_get_parent_services ();
 
-	top_services = tracker_ontology_get_top_services ();
+	for (l = parent_services; l; l = l->next) {
+		GArray      *subcategories;
+		const gchar *name;
+		gint         children = 0;
 
-	for (tops = top_services; tops != NULL; tops = tops->next) {
-		const gchar *top_name = NULL;
-		GArray *subcategories = NULL;
-		gint subcategories_items = 0;
-
-		top_name = tracker_service_get_name (tops->data);
+		name = tracker_service_get_name (l->data);
+		
+		if (!name) {
+			continue;
+		}
 
-		if (!top_name) continue;
+		subcategories = tracker_ontology_get_subcategory_ids (name);
 
-		subcategories = tracker_ontology_get_subcategory_ids (top_name);
+		if (!subcategories) {
+			continue;
+		}
 
 		for (i = 0; i < subcategories->len; i++) {
 			const gchar *subclass;
-			gpointer     amount;
+			gpointer     p;
 			gint         id;
 
 			id = g_array_index (subcategories, gint, i);
 			subclass = tracker_ontology_get_service_by_id (id);
-			amount = g_hash_table_lookup (values, subclass);
-			if (amount == NULL) continue;
-			
-			subcategories_items += GPOINTER_TO_INT (amount);
+			p = g_hash_table_lookup (values, subclass);
+			children += GPOINTER_TO_INT (p);
 		}
 
-		if (g_hash_table_lookup (values, tops->data)) {
-			g_hash_table_replace (values, 
-					      g_strdup (top_name), 
-					      GINT_TO_POINTER (subcategories_items));
-		} else {
-			g_hash_table_insert (values, 
-					     g_strdup (top_name), 
-					     GINT_TO_POINTER (subcategories_items));
-		}
+		g_hash_table_replace (values, 
+				      g_strdup (name), 
+				      GINT_TO_POINTER (children));
 	}
 
 	return values;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]