[tracker/tracker-0.10] tracker-store: Use lazy initialization for statistics
- From: Martyn James Russell <mr src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/tracker-0.10] tracker-store: Use lazy initialization for statistics
- Date: Thu, 12 May 2011 09:35:22 +0000 (UTC)
commit 2e8a062e45761fe8d5107c7cc2c4d23177e21678
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 | 24 +++++++++++++++++++++++-
2 files changed, 23 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..d1a92f1 100644
--- a/src/tracker-store/tracker-statistics.vala
+++ b/src/tracker-store/tracker-statistics.vala
@@ -21,10 +21,32 @@
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 */
+ 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]