[tracker/lazy-stats] tracker-store: Use lazy initialization for statistics



commit 1ba06170b97a0147577332fb35baca54d9e8b090
Author: Jürg Billeter <j bitron ch>
Date:   Fri May 6 13:19:46 2011 +0200

    tracker-store: Use lazy initialization for statistics
    
    This reduces startup time of tracker-store.

 src/libtracker-data/tracker-data-manager.c |   24 ------------------------
 src/tracker-store/tracker-statistics.vala  |   25 ++++++++++++++++++++++++-
 2 files changed, 24 insertions(+), 25 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index d68fddb..f6f9d6f 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -2173,30 +2173,6 @@ db_get_static_data (TrackerDBInterface *iface)
 			tracker_ontologies_add_id_uri_pair (id, uri);
 			tracker_class_set_id (class, id);
 
-			/* xsd classes do not derive from rdfs:Resource and do not use separate tables */
-			/* no need to fetch resource count if we are running in read-only mode (direct access) */
-			if (!g_str_has_prefix (tracker_class_get_name (class), "xsd:") &&
-			    (tracker_db_manager_get_flags (NULL, NULL) & TRACKER_DB_MANAGER_READONLY) == 0) {
-				/* update statistics */
-				stmt = tracker_db_interface_create_statement (iface, TRACKER_DB_STATEMENT_CACHE_TYPE_SELECT, &error,
-				                                              "SELECT COUNT(1) FROM \"%s\"",
-				                                              tracker_class_get_name (class));
-
-				if (error) {
-					g_warning ("%s", error->message);
-					g_clear_error (&error);
-				} else {
-					TrackerDBCursor *stat_cursor;
-
-					stat_cursor = tracker_db_statement_start_cursor (stmt, NULL);
-					tracker_db_cursor_iter_next (stat_cursor, NULL, NULL);
-					count = tracker_db_cursor_get_int (stat_cursor, 0);
-					tracker_class_set_count (class, count);
-					g_object_unref (stat_cursor);
-					g_object_unref (stmt);
-				}
-			}
-
 			g_object_unref (class);
 		}
 
diff --git a/src/tracker-store/tracker-statistics.vala b/src/tracker-store/tracker-statistics.vala
index b80d2bf..e536b89 100644
--- a/src/tracker-store/tracker-statistics.vala
+++ b/src/tracker-store/tracker-statistics.vala
@@ -21,10 +21,33 @@
 public class Tracker.Statistics : Object {
 	public const string PATH = "/org/freedesktop/Tracker1/Statistics";
 
+	static bool initialized;
+
 	[DBus (signature = "aas")]
-	public new Variant get (BusName sender) {
+	public new Variant get (BusName sender) throws GLib.Error {
 		var request = DBusRequest.begin (sender, "Statistics.Get");
 
+		if (!initialized) {
+			var iface = DBManager.get_db_interface ();
+
+			foreach (var cl in Ontologies.get_classes ()) {
+				/* xsd classes do not derive from rdfs:Resource and do not use separate tables */
+				/* no need to fetch resource count if we are running in read-only mode (direct access) */
+				if (!cl.name.has_prefix ("xsd:")) {
+					/* update statistics */
+					var stmt = iface.create_statement (DBStatementCacheType.NONE,
+						                           "SELECT COUNT(1) FROM \"%s\"",
+						                            cl.name);
+
+					var stat_cursor = stmt.start_cursor ();
+					stat_cursor.next ();
+					cl.count = (int) stat_cursor.get_integer (0);
+				}
+			}
+
+			initialized = true;
+		}
+
 		var builder = new VariantBuilder ((VariantType) "aas");
 
 		foreach (var cl in Ontologies.get_classes ()) {



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