[tracker/class-signal-perf-impr] libtracker-data, tracker-store: Performance improvement for class signals
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/class-signal-perf-impr] libtracker-data, tracker-store: Performance improvement for class signals
- Date: Tue, 15 Mar 2011 11:57:59 +0000 (UTC)
commit bcfcf1175f50d6c808ce5168443161cb4f91f995
Author: Philip Van Hoof <philip codeminded be>
Date: Tue Mar 15 12:57:26 2011 +0100
libtracker-data, tracker-store: Performance improvement for class signals
src/libtracker-data/libtracker-data.vapi | 1 +
src/tracker-store/tracker-backup.vala | 8 +--
src/tracker-store/tracker-events.c | 110 ++++++----------------------
src/tracker-store/tracker-events.h | 5 +-
src/tracker-store/tracker-events.vapi | 7 +--
src/tracker-store/tracker-locale-change.c | 4 +-
src/tracker-store/tracker-main.vala | 19 +-----
src/tracker-store/tracker-resources.vala | 33 ++++-----
8 files changed, 44 insertions(+), 143 deletions(-)
---
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index 5d92807..549b9f4 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -102,6 +102,7 @@ namespace Tracker {
[CCode (array_length = false, array_null_terminated = true)]
public unowned Class[] get_super_classes ();
public void transact_events ();
+ public bool notify { get; set; }
public bool has_insert_events ();
public bool has_delete_events ();
diff --git a/src/tracker-store/tracker-backup.vala b/src/tracker-store/tracker-backup.vala
index 8bc91b4..49df431 100644
--- a/src/tracker-store/tracker-backup.vala
+++ b/src/tracker-store/tracker-backup.vala
@@ -23,11 +23,9 @@ public class Tracker.Backup : Object {
public const string PATH = "/org/freedesktop/Tracker1/Backup";
public async void save (BusName sender, string destination_uri) throws Error {
- NotifyClassGetter getter = null;
var resources = (Resources) Tracker.DBus.get_object (typeof (Resources));
if (resources != null) {
resources.disable_signals ();
- getter = Tracker.Events.get_class_getter ();
Tracker.Events.shutdown ();
}
@@ -54,7 +52,7 @@ public class Tracker.Backup : Object {
throw e;
} finally {
if (resources != null) {
- Tracker.Events.init (getter);
+ Tracker.Events.init ();
resources.enable_signals ();
}
@@ -63,11 +61,9 @@ public class Tracker.Backup : Object {
}
public async void restore (BusName sender, string journal_uri) throws Error {
- NotifyClassGetter getter = null;
var resources = (Resources) Tracker.DBus.get_object (typeof (Resources));
if (resources != null) {
resources.disable_signals ();
- getter = Tracker.Events.get_class_getter ();
Tracker.Events.shutdown ();
}
@@ -88,7 +84,7 @@ public class Tracker.Backup : Object {
throw e;
} finally {
if (resources != null) {
- Tracker.Events.init (getter);
+ Tracker.Events.init ();
resources.enable_signals ();
}
diff --git a/src/tracker-store/tracker-events.c b/src/tracker-store/tracker-events.c
index eafeff6..cd13e67 100644
--- a/src/tracker-store/tracker-events.c
+++ b/src/tracker-store/tracker-events.c
@@ -27,11 +27,8 @@
#include "tracker-events.h"
typedef struct {
- GHashTable *allowances_id;
- GHashTable *allowances;
gboolean frozen;
guint total;
- TrackerNotifyClassGetter getter;
} EventsPrivate;
static EventsPrivate *private;
@@ -52,19 +49,6 @@ tracker_events_get_total (gboolean and_reset)
return total;
}
-static gboolean
-is_allowed (EventsPrivate *private, TrackerClass *rdf_class, gint class_id)
-{
- gboolean ret;
-
- if (rdf_class != NULL) {
- ret = (g_hash_table_lookup (private->allowances, rdf_class) != NULL) ? TRUE : FALSE;
- } else {
- ret = (g_hash_table_lookup (private->allowances_id, GINT_TO_POINTER (class_id)) != NULL) ? TRUE : FALSE;
- }
- return ret;
-}
-
void
tracker_events_add_insert (gint graph_id,
gint subject_id,
@@ -84,7 +68,7 @@ tracker_events_add_insert (gint graph_id,
}
for (i = 0; i < rdf_types->len; i++) {
- if (is_allowed (private, rdf_types->pdata[i], 0)) {
+ if (tracker_class_get_notify (rdf_types->pdata[i])) {
tracker_class_add_insert_event (rdf_types->pdata[i],
graph_id,
subject_id,
@@ -114,7 +98,7 @@ tracker_events_add_delete (gint graph_id,
}
for (i = 0; i < rdf_types->len; i++) {
- if (is_allowed (private, rdf_types->pdata[i], 0)) {
+ if (tracker_class_get_notify (rdf_types->pdata[i])) {
tracker_class_add_delete_event (rdf_types->pdata[i],
graph_id,
subject_id,
@@ -128,17 +112,20 @@ tracker_events_add_delete (gint graph_id,
void
tracker_events_reset_pending (void)
{
- GHashTableIter iter;
- gpointer key, value;
+ TrackerClass **classes;
+ guint length = 0;
+ guint i;
g_return_if_fail (private != NULL);
- g_hash_table_iter_init (&iter, private->allowances);
+ classes = tracker_ontologies_get_classes (&length);
- while (g_hash_table_iter_next (&iter, &key, &value)) {
- TrackerClass *class = key;
+ for (i = 0; i < length; i++) {
+ TrackerClass *class = classes[i];
- tracker_class_reset_pending_events (class);
+ if (tracker_class_get_notify (class)) {
+ tracker_class_reset_pending_events (class);
+ }
}
private->frozen = FALSE;
@@ -155,80 +142,31 @@ tracker_events_freeze (void)
static void
free_private (EventsPrivate *private)
{
- GHashTableIter iter;
- gpointer key, value;
-
- g_hash_table_iter_init (&iter, private->allowances);
+ TrackerClass **classes;
+ guint length = 0;
+ guint i;
- while (g_hash_table_iter_next (&iter, &key, &value)) {
- TrackerClass *class = key;
+ classes = tracker_ontologies_get_classes (&length);
- tracker_class_reset_pending_events (class);
+ for (i = 0; i < length; i++) {
+ TrackerClass *class = classes[i];
- /* Perhaps hurry an emit of the ready events here? We're shutting down,
- * so I guess we're not required to do that here ... ? */
- tracker_class_reset_ready_events (class);
+ if (tracker_class_get_notify (class)) {
+ tracker_class_reset_pending_events (class);
+ /* Perhaps hurry an emit of the ready events here? We're shutting down,
+ * so I guess we're not required to do that here ... ? */
+ tracker_class_reset_ready_events (class);
+ }
}
- g_hash_table_unref (private->allowances);
- g_hash_table_unref (private->allowances_id);
-
g_free (private);
}
-TrackerNotifyClassGetter
-tracker_events_get_class_getter (void)
-{
- g_return_val_if_fail (private != NULL, NULL);
- return private->getter;
-}
-
void
-tracker_events_init (TrackerNotifyClassGetter callback)
+tracker_events_init (void)
{
- GStrv classes_to_signal;
- gint i, count;
-
- if (!callback) {
- return;
- }
-
private = g_new0 (EventsPrivate, 1);
-
- private->allowances = g_hash_table_new (g_direct_hash, g_direct_equal);
- private->allowances_id = g_hash_table_new (g_direct_hash, g_direct_equal);
- private->getter = callback;
-
- classes_to_signal = (*callback)();
-
- if (!classes_to_signal)
- return;
-
- count = g_strv_length (classes_to_signal);
- for (i = 0; i < count; i++) {
- TrackerClass *class = tracker_ontologies_get_class_by_uri (classes_to_signal[i]);
- if (class != NULL) {
- g_hash_table_insert (private->allowances,
- class,
- GINT_TO_POINTER (TRUE));
- g_hash_table_insert (private->allowances_id,
- GINT_TO_POINTER (tracker_class_get_id (class)),
- GINT_TO_POINTER (TRUE));
- g_debug ("GraphUpdated allowance: %s has ID %d",
- tracker_class_get_name (class),
- tracker_class_get_id (class));
- }
- }
- g_strfreev (classes_to_signal);
-}
-
-void
-tracker_events_classes_iter (GHashTableIter *iter)
-{
- g_return_if_fail (private != NULL);
-
- g_hash_table_iter_init (iter, private->allowances);
}
void
diff --git a/src/tracker-store/tracker-events.h b/src/tracker-store/tracker-events.h
index cfb4fa7..dfeb754 100644
--- a/src/tracker-store/tracker-events.h
+++ b/src/tracker-store/tracker-events.h
@@ -30,9 +30,7 @@ G_BEGIN_DECLS
typedef GStrv (*TrackerNotifyClassGetter) (void);
-void tracker_events_init (TrackerNotifyClassGetter callback);
-TrackerNotifyClassGetter
- tracker_events_get_class_getter (void);
+void tracker_events_init (void);
void tracker_events_shutdown (void);
void tracker_events_add_insert (gint graph_id,
gint subject_id,
@@ -48,7 +46,6 @@ void tracker_events_add_delete (gint graph_id,
gint object_id,
const gchar *object,
GPtrArray *rdf_types);
-void tracker_events_classes_iter (GHashTableIter *iter);
guint tracker_events_get_total (gboolean and_reset);
void tracker_events_reset_pending (void);
void tracker_events_freeze (void);
diff --git a/src/tracker-store/tracker-events.vapi b/src/tracker-store/tracker-events.vapi
index 23bd415..154eceb 100644
--- a/src/tracker-store/tracker-events.vapi
+++ b/src/tracker-store/tracker-events.vapi
@@ -18,17 +18,12 @@
*/
namespace Tracker {
- [CCode (has_array_length = false, array_null_terminated = true, has_target = false, cheader_filename = "tracker-store/tracker-events.h")]
- public delegate string[] NotifyClassGetter ();
-
[CCode (cheader_filename = "tracker-store/tracker-events.h")]
namespace Events {
- public void init (NotifyClassGetter callback);
- public NotifyClassGetter get_class_getter ();
+ public void init ();
public void shutdown ();
public void add_insert (int graph_id, int subject_id, string subject, int pred_id, int object_id, string object, GLib.PtrArray rdf_types);
public void add_delete (int graph_id, int subject_id, string subject, int pred_id, int object_id, string object, GLib.PtrArray rdf_types);
- public GLib.HashTableIter<Tracker.Class, bool> classes_iter ();
public uint get_total (bool and_reset);
public void reset_pending ();
public void freeze ();
diff --git a/src/tracker-store/tracker-locale-change.c b/src/tracker-store/tracker-locale-change.c
index 0236643..e98a876 100644
--- a/src/tracker-store/tracker-locale-change.c
+++ b/src/tracker-store/tracker-locale-change.c
@@ -36,7 +36,6 @@
typedef struct {
gpointer resources;
- TrackerNotifyClassGetter getter;
} TrackerLocaleChangeContext;
/* Private */
@@ -77,7 +76,7 @@ locale_change_process_cb (GObject *source,
busy_destroy_notify (busy_user_data);
if (ctxt->resources) {
- tracker_events_init (ctxt->getter);
+ tracker_events_init ();
tracker_resources_enable_signals (ctxt->resources);
g_object_unref (ctxt->resources);
}
@@ -98,7 +97,6 @@ locale_change_process_idle_cb (gpointer data)
if (ctxt->resources) {
g_object_ref (ctxt->resources);
tracker_resources_disable_signals (ctxt->resources);
- ctxt->getter = tracker_events_get_class_getter ();
tracker_events_shutdown ();
}
diff --git a/src/tracker-store/tracker-main.vala b/src/tracker-store/tracker-main.vala
index f4bff34..05e06d6 100644
--- a/src/tracker-store/tracker-main.vala
+++ b/src/tracker-store/tracker-main.vala
@@ -127,23 +127,6 @@ License which can be viewed at:
}
[CCode (array_length = false, array_null_terminated = true)]
- static string[] get_notifiable_classes () {
- string[] classes_to_signal = null;
-
- try {
- var cursor = Tracker.Data.query_sparql_cursor ("SELECT ?class WHERE { ?class tracker:notify true }");
-
- while (cursor.next ()) {
- classes_to_signal += cursor.get_string (0);
- }
- } catch (Error e) {
- critical ("Unable to retrieve tracker:notify classes: %s", e.message);
- }
-
- return classes_to_signal;
- }
-
- [CCode (array_length = false, array_null_terminated = true)]
static string[] get_writeback_predicates () {
string[] predicates_to_signal = null;
@@ -313,7 +296,7 @@ License which can be viewed at:
Tracker.DBus.register_prepare_class_signal ();
- Tracker.Events.init (get_notifiable_classes);
+ Tracker.Events.init ();
Tracker.Writeback.init (get_writeback_predicates);
Tracker.Store.resume ();
diff --git a/src/tracker-store/tracker-resources.vala b/src/tracker-store/tracker-resources.vala
index 3ef3bb4..1d4b780 100644
--- a/src/tracker-store/tracker-resources.vala
+++ b/src/tracker-store/tracker-resources.vala
@@ -217,21 +217,17 @@ public class Tracker.Resources : Object {
bool on_emit_signals () {
bool had_any = false;
- /* Class signal feature */
- var iter = Tracker.Events.classes_iter ();
-
- unowned Class cl;
- bool value;
- while (iter.next (out cl, out value)) {
- if (emit_graph_updated (cl)) {
- had_any = true;
+ foreach (var cl in Tracker.Ontologies.get_classes ()) {
+ if (cl.notify) {
+ if (emit_graph_updated (cl)) {
+ had_any = true;
+ }
}
}
/* Reset counter */
Tracker.Events.get_total (true);
-
/* Writeback feature */
var writebacks = Tracker.Writeback.get_ready ();
@@ -272,12 +268,10 @@ public class Tracker.Resources : Object {
void on_statements_committed (bool start_timer) {
/* Class signal feature */
- var iter = Tracker.Events.classes_iter ();
-
- unowned Class cl;
- bool value;
- while (iter.next (out cl, out value)) {
- cl.transact_events ();
+ foreach (var cl in Tracker.Ontologies.get_classes ()) {
+ if (cl.notify) {
+ cl.transact_events ();
+ }
}
if (start_timer && signal_timeout == 0) {
@@ -296,12 +290,11 @@ public class Tracker.Resources : Object {
void check_graph_updated_signal () {
/* Check for whether we need an immediate emit */
if (Tracker.Events.get_total (false) > GRAPH_UPDATED_IMMEDIATE_EMIT_AT) {
- var iter = Tracker.Events.classes_iter ();
- unowned Class cl;
- bool value;
- while (iter.next (out cl, out value)) {
- emit_graph_updated (cl);
+ foreach (var cl in Tracker.Ontologies.get_classes ()) {
+ if (cl.notify) {
+ emit_graph_updated (cl);
+ }
}
/* Reset counter */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]