[tracker] libtracker-data, tracker-store: class-signal: Move the arrays to TrackerClass, optimization
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker] libtracker-data, tracker-store: class-signal: Move the arrays to TrackerClass, optimization
- Date: Wed, 1 Sep 2010 15:17:08 +0000 (UTC)
commit 6f8adf03e5915ca0a59239c7e3b009f8667baad3
Author: Philip Van Hoof <philip codeminded be>
Date: Thu Aug 19 11:07:03 2010 +0200
libtracker-data, tracker-store: class-signal: Move the arrays to TrackerClass, optimization
src/libtracker-data/tracker-class.c | 177 +++++++++++++++++++++++++++
src/libtracker-data/tracker-class.h | 86 +++++++++-----
src/tracker-store/tracker-events.c | 229 ++++++++++-------------------------
src/tracker-store/tracker-events.h | 4 -
4 files changed, 296 insertions(+), 200 deletions(-)
---
diff --git a/src/libtracker-data/tracker-class.c b/src/libtracker-data/tracker-class.c
index ebc1bfd..ef08520 100644
--- a/src/libtracker-data/tracker-class.c
+++ b/src/libtracker-data/tracker-class.c
@@ -44,6 +44,15 @@ struct _TrackerClassPrivate {
GArray *super_classes;
GArray *domain_indexes;
GArray *last_domain_indexes;
+
+ struct {
+ GArray *sub_pred_ids;
+ GArray *object_ids;
+ } deletes;
+ struct {
+ GArray *sub_pred_ids;
+ GArray *object_ids;
+ } inserts;
};
static void class_finalize (GObject *object);
@@ -72,6 +81,12 @@ tracker_class_init (TrackerClass *service)
priv->domain_indexes = g_array_new (TRUE, TRUE, sizeof (TrackerProperty *));
priv->last_domain_indexes = NULL;
+ priv->deletes.sub_pred_ids = g_array_new (FALSE, FALSE, sizeof (gint64));
+ priv->deletes.object_ids = g_array_new (FALSE, FALSE, sizeof (gint));
+
+ priv->inserts.sub_pred_ids = g_array_new (FALSE, FALSE, sizeof (gint64));
+ priv->inserts.object_ids = g_array_new (FALSE, FALSE, sizeof (gint));
+
/* Make GET_PRIV working */
service->priv = priv;
}
@@ -89,6 +104,12 @@ class_finalize (GObject *object)
g_array_free (priv->super_classes, TRUE);
g_array_free (priv->domain_indexes, TRUE);
+ g_array_free (priv->deletes.sub_pred_ids, TRUE);
+ g_array_free (priv->deletes.object_ids, TRUE);
+
+ g_array_free (priv->inserts.sub_pred_ids, TRUE);
+ g_array_free (priv->inserts.object_ids, TRUE);
+
if (priv->last_domain_indexes)
g_array_free (priv->last_domain_indexes, TRUE);
@@ -402,3 +423,159 @@ tracker_class_set_db_schema_changed (TrackerClass *service,
priv->db_schema_changed = value;
}
+
+gboolean
+tracker_class_has_insert_events (TrackerClass *class)
+{
+ TrackerClassPrivate *priv;
+
+ g_return_val_if_fail (TRACKER_IS_CLASS (class), FALSE);
+
+ priv = GET_PRIV (class);
+
+ return (priv->inserts.sub_pred_ids->len > 0);
+}
+
+gboolean
+tracker_class_has_delete_events (TrackerClass *class)
+{
+ TrackerClassPrivate *priv;
+
+ g_return_val_if_fail (TRACKER_IS_CLASS (class), FALSE);
+
+ priv = GET_PRIV (class);
+
+ return (priv->deletes.sub_pred_ids->len > 0);
+}
+
+void
+tracker_class_foreach_insert_event (TrackerClass *class,
+ TrackerEventsForeach foreach,
+ gpointer user_data)
+{
+ guint i;
+ TrackerClassPrivate *priv;
+
+ g_return_if_fail (TRACKER_IS_CLASS (class));
+ g_return_if_fail (foreach != NULL);
+
+ priv = GET_PRIV (class);
+
+ for (i = 0; i < priv->inserts.sub_pred_ids->len; i++) {
+ gint subject_id, pred_id, object_id;
+ gint64 sub_pred_id;
+
+ sub_pred_id = g_array_index (priv->inserts.sub_pred_ids, gint64, i);
+ pred_id = sub_pred_id & 0xffffffff;
+ subject_id = sub_pred_id >> 32;
+ object_id = g_array_index (priv->inserts.object_ids, gint, i);
+
+ foreach (subject_id, pred_id, object_id, user_data);
+ }
+}
+
+void
+tracker_class_foreach_delete_event (TrackerClass *class,
+ TrackerEventsForeach foreach,
+ gpointer user_data)
+{
+ guint i;
+ TrackerClassPrivate *priv;
+
+ g_return_if_fail (TRACKER_IS_CLASS (class));
+ g_return_if_fail (foreach != NULL);
+
+ priv = GET_PRIV (class);
+
+ for (i = 0; i < priv->deletes.sub_pred_ids->len; i++) {
+ gint subject_id, pred_id, object_id;
+ gint64 sub_pred_id;
+
+ sub_pred_id = g_array_index (priv->deletes.sub_pred_ids, gint64, i);
+ pred_id = sub_pred_id & 0xffffffff;
+ subject_id = sub_pred_id >> 32;
+ object_id = g_array_index (priv->deletes.object_ids, gint, i);
+
+ foreach (subject_id, pred_id, object_id, user_data);
+ }
+}
+
+void
+tracker_class_reset_events (TrackerClass *class)
+{
+ TrackerClassPrivate *priv;
+
+ g_return_if_fail (TRACKER_IS_CLASS (class));
+ priv = GET_PRIV (class);
+
+ g_array_set_size (priv->deletes.sub_pred_ids, 0);
+ g_array_set_size (priv->deletes.object_ids, 0);
+
+ g_array_set_size (priv->inserts.sub_pred_ids, 0);
+ g_array_set_size (priv->inserts.object_ids, 0);
+}
+
+static void
+insert_vals_into_arrays (GArray *sub_pred_ids,
+ GArray *object_ids,
+ gint subject_id,
+ gint pred_id,
+ gint object_id)
+{
+ guint i;
+ gboolean inserted = FALSE;
+ gint64 sub_pred_id;
+
+ sub_pred_id = (gint64) subject_id;
+ sub_pred_id = sub_pred_id << 32 | pred_id;
+
+ for (i = 0; i < sub_pred_ids->len; i++) {
+ if (sub_pred_id < g_array_index (sub_pred_ids, gint64, i)) {
+ g_array_insert_val (sub_pred_ids, i, sub_pred_id);
+ g_array_insert_val (object_ids, i, object_id);
+ inserted = TRUE;
+ break;
+ }
+ }
+
+ if (!inserted) {
+ g_array_append_val (sub_pred_ids, sub_pred_id);
+ g_array_append_val (object_ids, object_id);
+ }
+}
+
+void
+tracker_class_add_insert_event (TrackerClass *class,
+ gint subject_id,
+ gint pred_id,
+ gint object_id)
+{
+ TrackerClassPrivate *priv;
+
+ g_return_if_fail (TRACKER_IS_CLASS (class));
+ priv = GET_PRIV (class);
+
+ insert_vals_into_arrays (priv->inserts.sub_pred_ids,
+ priv->inserts.object_ids,
+ subject_id,
+ pred_id,
+ object_id);
+}
+
+void
+tracker_class_add_delete_event (TrackerClass *class,
+ gint subject_id,
+ gint pred_id,
+ gint object_id)
+{
+ TrackerClassPrivate *priv;
+
+ g_return_if_fail (TRACKER_IS_CLASS (class));
+ priv = GET_PRIV (class);
+
+ insert_vals_into_arrays (priv->deletes.sub_pred_ids,
+ priv->deletes.object_ids,
+ subject_id,
+ pred_id,
+ object_id);
+}
diff --git a/src/libtracker-data/tracker-class.h b/src/libtracker-data/tracker-class.h
index bc80324..d3e3fbe 100644
--- a/src/libtracker-data/tracker-class.h
+++ b/src/libtracker-data/tracker-class.h
@@ -50,39 +50,63 @@ struct _TrackerClassClass {
GObjectClass parent_class;
};
+typedef void (*TrackerEventsForeach) (gint subject_id,
+ gint pred_id,
+ gint object_id,
+ gpointer user_data);
+
GType tracker_class_get_type (void) G_GNUC_CONST;
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);
-gint tracker_class_get_id (TrackerClass *service);
-gboolean tracker_class_get_is_new (TrackerClass *service);
-gboolean tracker_class_get_db_schema_changed (TrackerClass *service);
-gboolean tracker_class_get_notify (TrackerClass *service);
-
-TrackerClass **tracker_class_get_super_classes (TrackerClass *service);
-TrackerProperty **tracker_class_get_domain_indexes (TrackerClass *service);
-TrackerProperty **tracker_class_get_last_domain_indexes(TrackerClass *service);
-
-void tracker_class_set_uri (TrackerClass *service,
- const gchar *value);
-void tracker_class_set_count (TrackerClass *service,
- gint value);
-void tracker_class_add_super_class (TrackerClass *service,
- TrackerClass *value);
-void tracker_class_add_domain_index (TrackerClass *service,
- TrackerProperty *value);
-void tracker_class_del_domain_index (TrackerClass *service,
- TrackerProperty *value);
-void tracker_class_reset_domain_indexes (TrackerClass *service);
-void tracker_class_set_id (TrackerClass *service,
- gint id);
-void tracker_class_set_is_new (TrackerClass *service,
- gboolean value);
-void tracker_class_set_db_schema_changed (TrackerClass *service,
- gboolean value);
-void tracker_class_set_notify (TrackerClass *service,
- gboolean value);
+const gchar * tracker_class_get_uri (TrackerClass *service);
+const gchar * tracker_class_get_name (TrackerClass *service);
+gint tracker_class_get_count (TrackerClass *service);
+gint tracker_class_get_id (TrackerClass *service);
+gboolean tracker_class_get_is_new (TrackerClass *service);
+gboolean tracker_class_get_db_schema_changed (TrackerClass *service);
+gboolean tracker_class_get_notify (TrackerClass *service);
+
+TrackerClass **tracker_class_get_super_classes (TrackerClass *service);
+TrackerProperty **tracker_class_get_domain_indexes (TrackerClass *service);
+TrackerProperty **tracker_class_get_last_domain_indexes(TrackerClass *service);
+
+void tracker_class_set_uri (TrackerClass *service,
+ const gchar *value);
+void tracker_class_set_count (TrackerClass *service,
+ gint value);
+void tracker_class_add_super_class (TrackerClass *service,
+ TrackerClass *value);
+void tracker_class_add_domain_index (TrackerClass *service,
+ TrackerProperty *value);
+void tracker_class_del_domain_index (TrackerClass *service,
+ TrackerProperty *value);
+void tracker_class_reset_domain_indexes (TrackerClass *service);
+void tracker_class_set_id (TrackerClass *service,
+ gint id);
+void tracker_class_set_is_new (TrackerClass *service,
+ gboolean value);
+void tracker_class_set_db_schema_changed (TrackerClass *service,
+ gboolean value);
+void tracker_class_set_notify (TrackerClass *service,
+ gboolean value);
+
+/* For signals API */
+void tracker_class_foreach_delete_event (TrackerClass *class,
+ TrackerEventsForeach foreach,
+ gpointer user_data);
+void tracker_class_foreach_insert_event (TrackerClass *class,
+ TrackerEventsForeach foreach,
+ gpointer user_data);
+gboolean tracker_class_has_insert_events (TrackerClass *class);
+gboolean tracker_class_has_delete_events (TrackerClass *class);
+void tracker_class_reset_events (TrackerClass *class);
+void tracker_class_add_delete_event (TrackerClass *class,
+ gint subject_id,
+ gint pred_id,
+ gint object_id);
+void tracker_class_add_insert_event (TrackerClass *class,
+ gint subject_id,
+ gint pred_id,
+ gint object_id);
G_END_DECLS
diff --git a/src/tracker-store/tracker-events.c b/src/tracker-store/tracker-events.c
index 99aff8d..daa8e04 100644
--- a/src/tracker-store/tracker-events.c
+++ b/src/tracker-store/tracker-events.c
@@ -29,16 +29,6 @@
typedef struct {
GHashTable *allowances_id;
GHashTable *allowances;
- struct {
- GArray *sub_pred_ids;
- GArray *object_ids;
- GArray *class_ids;
- } deletes;
- struct {
- GArray *sub_pred_ids;
- GArray *object_ids;
- GArray *class_ids;
- } inserts;
gboolean frozen;
} EventsPrivate;
@@ -49,32 +39,10 @@ tracker_events_foreach_insert_of (TrackerClass *class,
TrackerEventsForeach foreach,
gpointer user_data)
{
- guint i;
- gint class_id;
-
- g_return_if_fail (private != NULL);
g_return_if_fail (class != NULL);
g_return_if_fail (foreach != NULL);
- class_id = tracker_class_get_id (class);
-
- for (i = 0; i < private->inserts.class_ids->len; i++) {
- gint class_id_v;
-
- class_id_v = g_array_index (private->inserts.class_ids, gint, i);
-
- if (class_id_v == class_id) {
- gint subject_id, pred_id, object_id;
- gint64 sub_pred_id;
-
- sub_pred_id = g_array_index (private->inserts.sub_pred_ids, gint64, i);
- pred_id = sub_pred_id & 0xffffffff;
- subject_id = sub_pred_id >> 32;
- object_id = g_array_index (private->inserts.object_ids, gint, i);
-
- foreach (subject_id, pred_id, object_id, user_data);
- }
- }
+ tracker_class_foreach_insert_event (class, foreach, user_data);
}
void
@@ -82,80 +50,26 @@ tracker_events_foreach_delete_of (TrackerClass *class,
TrackerEventsForeach foreach,
gpointer user_data)
{
- guint i;
- gint class_id;
-
- g_return_if_fail (private != NULL);
g_return_if_fail (class != NULL);
g_return_if_fail (foreach != NULL);
- class_id = tracker_class_get_id (class);
-
- for (i = 0; i < private->deletes.class_ids->len; i++) {
- gint class_id_v;
-
- class_id_v = g_array_index (private->deletes.class_ids, gint, i);
-
- if (class_id_v == class_id) {
- gint subject_id, pred_id, object_id;
- gint64 sub_pred_id;
-
- sub_pred_id = g_array_index (private->deletes.sub_pred_ids, gint64, i);
- pred_id = sub_pred_id & 0xffffffff;
- subject_id = sub_pred_id >> 32;
- object_id = g_array_index (private->deletes.object_ids, gint, i);
-
- foreach (subject_id, pred_id, object_id, user_data);
- }
- }
+ tracker_class_foreach_delete_event (class, foreach, user_data);
}
gboolean
tracker_events_class_has_deletes (TrackerClass *class)
{
- guint i;
- gint class_id;
-
- g_return_val_if_fail (private != NULL, FALSE);
g_return_val_if_fail (class != NULL, FALSE);
- class_id = tracker_class_get_id (class);
-
- for (i = 0; i < private->deletes.class_ids->len; i++) {
- gint class_id_v;
-
- class_id_v = g_array_index (private->deletes.class_ids, gint, i);
-
- if (class_id_v == class_id) {
- return TRUE;
- }
- }
-
- return FALSE;
+ return tracker_class_has_delete_events (class);
}
gboolean
tracker_events_class_has_inserts (TrackerClass *class)
{
- guint i;
- gint class_id;
-
- g_return_val_if_fail (private != NULL, FALSE);
g_return_val_if_fail (class != NULL, FALSE);
- class_id = tracker_class_get_id (class);
-
- for (i = 0; i < private->inserts.class_ids->len; i++) {
- gint class_id_v;
-
- class_id_v = g_array_index (private->inserts.class_ids, gint, i);
-
- if (class_id_v == class_id) {
- return TRUE;
- }
- }
-
- return FALSE;
+ return tracker_class_has_insert_events (class);
}
static gboolean
@@ -171,39 +85,6 @@ is_allowed (EventsPrivate *private, TrackerClass *rdf_class, gint class_id)
return ret;
}
-static void
-insert_vals_into_arrays (GArray *class_ids,
- GArray *sub_pred_ids,
- GArray *object_ids,
- gint class_id,
- gint subject_id,
- gint pred_id,
- gint object_id)
-{
- guint i;
- gboolean inserted = FALSE;
- gint64 sub_pred_id;
-
- sub_pred_id = (gint64) subject_id;
- sub_pred_id = sub_pred_id << 32 | pred_id;
-
- for (i = 0; i < sub_pred_ids->len; i++) {
- if (sub_pred_id < g_array_index (sub_pred_ids, gint64, i)) {
- g_array_insert_val (class_ids, i, class_id);
- g_array_insert_val (sub_pred_ids, i, sub_pred_id);
- g_array_insert_val (object_ids, i, object_id);
- inserted = TRUE;
- break;
- }
- }
-
- if (!inserted) {
- g_array_append_val (class_ids, class_id);
- g_array_append_val (sub_pred_ids, sub_pred_id);
- g_array_append_val (object_ids, object_id);
- }
-}
-
void
tracker_events_add_insert (gint graph_id,
gint subject_id,
@@ -228,22 +109,32 @@ tracker_events_add_insert (gint graph_id,
/* Resource create
* In case of create, object is the rdf:type */
if (is_allowed (private, NULL, object_id)) {
- insert_vals_into_arrays (private->inserts.class_ids,
- private->inserts.sub_pred_ids,
- private->inserts.object_ids,
- object_id,
- subject_id, pred_id, object_id);
+ const gchar *uri;
+
+ /* Double hashtable lookup can be optimized: the class might also be
+ * in rdf_types (need to check this) */
+
+ uri = tracker_ontologies_get_uri_by_id (object_id);
+ if (uri) {
+ TrackerClass *class;
+ class = tracker_ontologies_get_class_by_uri (uri);
+ if (class) {
+ tracker_class_add_delete_event (class,
+ subject_id,
+ pred_id,
+ object_id);
+ }
+ }
}
} else {
guint i;
for (i = 0; i < rdf_types->len; i++) {
if (is_allowed (private, rdf_types->pdata[i], 0)) {
- insert_vals_into_arrays (private->inserts.class_ids,
- private->inserts.sub_pred_ids,
- private->inserts.object_ids,
- tracker_class_get_id (rdf_types->pdata[i]),
- subject_id, pred_id, object_id);
+ tracker_class_add_delete_event (rdf_types->pdata[i],
+ subject_id,
+ pred_id,
+ object_id);
}
}
}
@@ -273,22 +164,32 @@ tracker_events_add_delete (gint graph_id,
/* Resource delete
* In case of delete, object is the rdf:type */
if (is_allowed (private, NULL, object_id)) {
- insert_vals_into_arrays (private->deletes.class_ids,
- private->deletes.sub_pred_ids,
- private->deletes.object_ids,
- object_id,
- subject_id, pred_id, object_id);
+ const gchar *uri;
+
+ /* Double hashtable lookup can be optimized: the class might also be
+ * in rdf_types (need to check this) */
+
+ uri = tracker_ontologies_get_uri_by_id (object_id);
+ if (uri) {
+ TrackerClass *class;
+ class = tracker_ontologies_get_class_by_uri (uri);
+ if (class) {
+ tracker_class_add_delete_event (class,
+ subject_id,
+ pred_id,
+ object_id);
+ }
+ }
}
} else {
guint i;
for (i = 0; i < rdf_types->len; i++) {
if (is_allowed (private, rdf_types->pdata[i], 0)) {
- insert_vals_into_arrays (private->deletes.class_ids,
- private->deletes.sub_pred_ids,
- private->deletes.object_ids,
- tracker_class_get_id (rdf_types->pdata[i]),
- subject_id, pred_id, object_id);
+ tracker_class_add_delete_event (rdf_types->pdata[i],
+ subject_id,
+ pred_id,
+ object_id);
}
}
}
@@ -298,15 +199,18 @@ tracker_events_add_delete (gint graph_id,
void
tracker_events_reset (void)
{
+ GHashTableIter iter;
+ gpointer key, value;
+
g_return_if_fail (private != NULL);
- g_array_set_size (private->deletes.class_ids, 0);
- g_array_set_size (private->deletes.sub_pred_ids, 0);
- g_array_set_size (private->deletes.object_ids, 0);
+ g_hash_table_iter_init (&iter, private->allowances);
- g_array_set_size (private->inserts.class_ids, 0);
- g_array_set_size (private->inserts.sub_pred_ids, 0);
- g_array_set_size (private->inserts.object_ids, 0);
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ TrackerClass *class = key;
+
+ tracker_class_reset_events (class);
+ }
private->frozen = FALSE;
}
@@ -322,16 +226,19 @@ tracker_events_freeze (void)
static void
free_private (EventsPrivate *private)
{
- g_hash_table_unref (private->allowances);
- g_hash_table_unref (private->allowances_id);
+ GHashTableIter iter;
+ gpointer key, value;
- g_array_free (private->deletes.class_ids, TRUE);
- g_array_free (private->deletes.sub_pred_ids, TRUE);
- g_array_free (private->deletes.object_ids, TRUE);
+ g_hash_table_iter_init (&iter, private->allowances);
- g_array_free (private->inserts.class_ids, TRUE);
- g_array_free (private->inserts.sub_pred_ids, TRUE);
- g_array_free (private->inserts.object_ids, TRUE);
+ while (g_hash_table_iter_next (&iter, &key, &value)) {
+ TrackerClass *class = key;
+
+ tracker_class_reset_events (class);
+ }
+
+ g_hash_table_unref (private->allowances);
+ g_hash_table_unref (private->allowances_id);
g_free (private);
}
@@ -351,14 +258,6 @@ tracker_events_init (TrackerNotifyClassGetter callback)
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->deletes.class_ids = g_array_new (FALSE, FALSE, sizeof (gint));
- private->deletes.sub_pred_ids = g_array_new (FALSE, FALSE, sizeof (gint64));
- private->deletes.object_ids = g_array_new (FALSE, FALSE, sizeof (gint));
-
- private->inserts.class_ids = g_array_new (FALSE, FALSE, sizeof (gint));
- private->inserts.sub_pred_ids = g_array_new (FALSE, FALSE, sizeof (gint64));
- private->inserts.object_ids = g_array_new (FALSE, FALSE, sizeof (gint));
-
classes_to_signal = (*callback)();
if (!classes_to_signal)
diff --git a/src/tracker-store/tracker-events.h b/src/tracker-store/tracker-events.h
index bc3b085..20f19db 100644
--- a/src/tracker-store/tracker-events.h
+++ b/src/tracker-store/tracker-events.h
@@ -29,10 +29,6 @@
G_BEGIN_DECLS
typedef GStrv (*TrackerNotifyClassGetter) (void);
-typedef void (*TrackerEventsForeach) (gint subject_id,
- gint pred_id,
- gint object_id,
- gpointer user_data);
void tracker_events_init (TrackerNotifyClassGetter callback);
void tracker_events_shutdown (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]