[tracker] Update statistics continuously
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tracker] Update statistics continuously
- Date: Mon, 7 Sep 2009 16:08:15 +0000 (UTC)
commit 3f3a9f9529ebe320a476faf43bda9d7d951db0c0
Author: Jürg Billeter <j bitron ch>
Date: Mon Sep 7 18:01:01 2009 +0200
Update statistics continuously
Fixes NB#120451.
src/libtracker-common/tracker-class.c | 45 +++++++++++++++++++++++++++-
src/libtracker-common/tracker-class.h | 3 ++
src/libtracker-data/tracker-data-manager.c | 13 ++++++++
src/libtracker-data/tracker-data-update.c | 4 ++
src/tracker-store/tracker-statistics.c | 22 ++++++-------
5 files changed, 74 insertions(+), 13 deletions(-)
---
diff --git a/src/libtracker-common/tracker-class.c b/src/libtracker-common/tracker-class.c
index 0d95f04..7b40582 100644
--- a/src/libtracker-common/tracker-class.c
+++ b/src/libtracker-common/tracker-class.c
@@ -35,6 +35,7 @@ typedef struct _TrackerClassPriv TrackerClassPriv;
struct _TrackerClassPriv {
gchar *uri;
gchar *name;
+ gint count;
GArray *super_classes;
};
@@ -52,7 +53,8 @@ static void class_set_property (GObject *object,
enum {
PROP_0,
PROP_URI,
- PROP_NAME
+ PROP_NAME,
+ PROP_COUNT
};
G_DEFINE_TYPE (TrackerClass, tracker_class, G_TYPE_OBJECT);
@@ -80,6 +82,15 @@ tracker_class_class_init (TrackerClassClass *klass)
"Service name",
NULL,
G_PARAM_READABLE));
+ g_object_class_install_property (object_class,
+ PROP_NAME,
+ g_param_spec_int ("count",
+ "count",
+ "Count",
+ 0,
+ INT_MAX,
+ 0,
+ G_PARAM_READABLE | G_PARAM_WRITABLE));
g_type_class_add_private (object_class, sizeof (TrackerClassPriv));
}
@@ -126,6 +137,9 @@ class_get_property (GObject *object,
case PROP_NAME:
g_value_set_string (value, priv->name);
break;
+ case PROP_COUNT:
+ g_value_set_int (value, priv->count);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -143,6 +157,10 @@ class_set_property (GObject *object,
tracker_class_set_uri (TRACKER_CLASS (object),
g_value_get_string (value));
break;
+ case PROP_COUNT:
+ tracker_class_set_count (TRACKER_CLASS (object),
+ g_value_get_int (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
@@ -183,6 +201,18 @@ tracker_class_get_name (TrackerClass *service)
return priv->name;
}
+gint
+tracker_class_get_count (TrackerClass *service)
+{
+ TrackerClassPriv *priv;
+
+ g_return_val_if_fail (TRACKER_IS_CLASS (service), 0);
+
+ priv = GET_PRIV (service);
+
+ return priv->count;
+}
+
TrackerClass **
tracker_class_get_super_classes (TrackerClass *service)
{
@@ -239,6 +269,19 @@ tracker_class_set_uri (TrackerClass *service,
}
void
+tracker_class_set_count (TrackerClass *service,
+ gint value)
+{
+ TrackerClassPriv *priv;
+
+ g_return_if_fail (TRACKER_IS_CLASS (service));
+
+ priv = GET_PRIV (service);
+
+ priv->count = value;
+}
+
+void
tracker_class_set_super_classes (TrackerClass *service,
TrackerClass **value)
{
diff --git a/src/libtracker-common/tracker-class.h b/src/libtracker-common/tracker-class.h
index 5123b03..c822251 100644
--- a/src/libtracker-common/tracker-class.h
+++ b/src/libtracker-common/tracker-class.h
@@ -54,10 +54,13 @@ TrackerClass *tracker_class_new (void);
const gchar * tracker_class_get_uri (TrackerClass *service);
const gchar * tracker_class_get_name (TrackerClass *service);
+gint tracker_class_get_count (TrackerClass *service);
TrackerClass **tracker_class_get_super_classes (TrackerClass *service);
void tracker_class_set_uri (TrackerClass *service,
const gchar *value);
+void tracker_class_set_count (TrackerClass *service,
+ gint value);
void tracker_class_set_super_classes (TrackerClass *self,
TrackerClass **super_classes);
void tracker_class_add_super_class (TrackerClass *self,
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 582f545..0cf0a48 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -341,6 +341,7 @@ db_get_static_data (TrackerDBInterface *iface)
{
TrackerDBStatement *stmt;
TrackerDBCursor *cursor;
+ TrackerDBResultSet *result_set;
stmt = tracker_db_interface_create_statement (iface,
"SELECT (SELECT Uri FROM \"rdfs:Resource\" WHERE ID = \"tracker:Namespace\".ID), "
@@ -380,6 +381,7 @@ db_get_static_data (TrackerDBInterface *iface)
while (tracker_db_cursor_iter_next (cursor)) {
TrackerClass *class;
const gchar *uri;
+ gint count;
class = tracker_class_new ();
@@ -389,6 +391,17 @@ db_get_static_data (TrackerDBInterface *iface)
class_add_super_classes_from_db (iface, class);
tracker_ontology_add_class (class);
+ /* xsd classes do not derive from rdfs:Resource and do not use separate tables */
+ if (!g_str_has_prefix (tracker_class_get_name (class), "xsd:")) {
+ /* update statistics */
+ stmt = tracker_db_interface_create_statement (iface, "SELECT COUNT(1) FROM \"%s\"", tracker_class_get_name (class));
+ result_set = tracker_db_statement_execute (stmt, NULL);
+ tracker_db_result_set_get (result_set, 0, &count, -1);
+ tracker_class_set_count (class, count);
+ g_object_unref (result_set);
+ g_object_unref (stmt);
+ }
+
g_object_unref (class);
}
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 0455d46..f6ec8e5 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -536,6 +536,8 @@ cache_create_service_decomposed (TrackerClass *cl)
}
}
+ tracker_class_set_count (cl, tracker_class_get_count (cl) + 1);
+
g_ptr_array_add (update_buffer.types, g_strdup (class_uri));
g_value_init (&gvalue, G_TYPE_INT);
@@ -1110,6 +1112,8 @@ tracker_data_delete_statement (const gchar *subject,
/* delete rows from class tables */
delete_resource_type (subject_id, class);
+
+ tracker_class_set_count (class, tracker_class_get_count (class) - 1);
} else {
g_set_error (error, TRACKER_DATA_ERROR, TRACKER_DATA_ERROR_UNKNOWN_CLASS,
"Class '%s' not found in the ontology", object);
diff --git a/src/tracker-store/tracker-statistics.c b/src/tracker-store/tracker-statistics.c
index 2e68e54..6cc10f0 100644
--- a/src/tracker-store/tracker-statistics.c
+++ b/src/tracker-store/tracker-statistics.c
@@ -208,11 +208,11 @@ tracker_statistics_get (TrackerStatistics *object,
DBusGMethodInvocation *context,
GError **error)
{
+ TrackerClass **classes;
+ TrackerClass **cl;
TrackerStatisticsPrivate *priv;
guint request_id;
GPtrArray *values;
- GHashTableIter iter;
- gpointer key, value;
request_id = tracker_dbus_get_next_request_id ();
@@ -223,28 +223,26 @@ tracker_statistics_get (TrackerStatistics *object,
values = g_ptr_array_new ();
- g_hash_table_iter_init (&iter, priv->cache);
- while (g_hash_table_iter_next (&iter, &key, &value)) {
- GStrv strv;
- const gchar *service_type;
- gint count;
+ classes = tracker_ontology_get_classes ();
- service_type = key;
- count = GPOINTER_TO_INT (value);
+ for (cl = classes; *cl; cl++) {
+ GStrv strv;
- if (count == 0) {
+ if (tracker_class_get_count (*cl) == 0) {
/* skip classes without resources */
continue;
}
strv = g_new (gchar*, 3);
- strv[0] = g_strdup (service_type);
- strv[1] = g_strdup_printf ("%d", count);
+ strv[0] = g_strdup (tracker_class_get_name (*cl));
+ strv[1] = g_strdup_printf ("%d", tracker_class_get_count (*cl));
strv[2] = NULL;
g_ptr_array_add (values, strv);
}
+ g_free (classes);
+
/* Sort result so it is alphabetical */
g_ptr_array_sort (values, cache_sort_func);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]