[tracker/wip/carlosg/sparql1.1: 51/113] libtracker-data: Drop TrackerClass count parameter
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/sparql1.1: 51/113] libtracker-data: Drop TrackerClass count parameter
- Date: Sun, 21 Jul 2019 14:33:30 +0000 (UTC)
commit e9630df716eba857e2e110ad15337ac77eba796c
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Jun 16 21:29:51 2019 +0200
libtracker-data: Drop TrackerClass count parameter
It used to keep accounting of how many resources of the given TrackerClass
there are, but it's largely unused. Funnily, the Statistics tracker-store
interface only used tracker_class_set/get_count() as storage for its own
accounting, so just make it have a hashtable.
src/libtracker-data/libtracker-data.vapi | 1 -
src/libtracker-data/tracker-class.c | 27 ---------------
src/libtracker-data/tracker-class.h | 3 --
src/libtracker-data/tracker-data-update.c | 55 -------------------------------
src/tracker-store/tracker-statistics.vala | 38 ++++++++++-----------
5 files changed, 18 insertions(+), 106 deletions(-)
---
diff --git a/src/libtracker-data/libtracker-data.vapi b/src/libtracker-data/libtracker-data.vapi
index be1bcf118..4327be918 100644
--- a/src/libtracker-data/libtracker-data.vapi
+++ b/src/libtracker-data/libtracker-data.vapi
@@ -122,7 +122,6 @@ namespace Tracker {
public class Class : GLib.Object {
public string name { get; set; }
public string uri { get; set; }
- public int count { get; set; }
[CCode (array_length = false, array_null_terminated = true)]
public unowned Class[] get_super_classes ();
public void transact_events ();
diff --git a/src/libtracker-data/tracker-class.c b/src/libtracker-data/tracker-class.c
index 76d5416c9..47bf8439f 100644
--- a/src/libtracker-data/tracker-class.c
+++ b/src/libtracker-data/tracker-class.c
@@ -34,7 +34,6 @@ typedef struct _TrackerClassPrivate TrackerClassPrivate;
struct _TrackerClassPrivate {
gchar *uri;
gchar *name;
- gint count;
gint id;
gboolean is_new;
gboolean db_schema_changed;
@@ -140,18 +139,6 @@ tracker_class_get_name (TrackerClass *service)
return priv->name;
}
-gint
-tracker_class_get_count (TrackerClass *service)
-{
- TrackerClassPrivate *priv;
-
- g_return_val_if_fail (TRACKER_IS_CLASS (service), 0);
-
- priv = tracker_class_get_instance_private (service);
-
- return priv->count;
-}
-
gint
tracker_class_get_id (TrackerClass *service)
{
@@ -312,20 +299,6 @@ tracker_class_set_uri (TrackerClass *service,
}
}
-void
-tracker_class_set_count (TrackerClass *service,
- gint value)
-{
- TrackerClassPrivate *priv;
-
- g_return_if_fail (TRACKER_IS_CLASS (service));
-
- priv = tracker_class_get_instance_private (service);
-
- priv->count = value;
-}
-
-
void
tracker_class_set_id (TrackerClass *service,
gint value)
diff --git a/src/libtracker-data/tracker-class.h b/src/libtracker-data/tracker-class.h
index 1c01e8914..004c6660c 100644
--- a/src/libtracker-data/tracker-class.h
+++ b/src/libtracker-data/tracker-class.h
@@ -53,7 +53,6 @@ GType tracker_class_get_type (void) G_GNUC_CONST;
TrackerClass * tracker_class_new (gboolean use_gvdb);
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);
@@ -66,8 +65,6 @@ TrackerClass **tracker_class_get_last_super_classes (TrackerClass *ser
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,
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index c2bb92191..949bb9dd9 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -54,10 +54,6 @@ struct _TrackerDataUpdateBuffer {
/* string -> TrackerDataUpdateBufferGraph */
GPtrArray *graphs;
- /* the following two fields are valid per sqlite transaction, not just for same subject */
- /* TrackerClass -> integer */
- GHashTable *class_counts;
-
#if HAVE_TRACKER_FTS
gboolean fts_ever_updated;
#endif
@@ -749,25 +745,6 @@ statement_bind_gvalue (TrackerDBStatement *stmt,
}
}
-static void
-add_class_count (TrackerData *data,
- TrackerClass *class,
- gint count)
-{
- gint old_count_entry;
-
- tracker_class_set_count (class, tracker_class_get_count (class) + count);
-
- /* update class_counts table so that the count change can be reverted in case of rollback */
- if (!data->update_buffer.class_counts) {
- data->update_buffer.class_counts = g_hash_table_new (g_direct_hash, g_direct_equal);
- }
-
- old_count_entry = GPOINTER_TO_INT (g_hash_table_lookup (data->update_buffer.class_counts, class));
- g_hash_table_insert (data->update_buffer.class_counts, class,
- GINT_TO_POINTER (old_count_entry + count));
-}
-
static void
tracker_data_resource_buffer_flush (TrackerData *data,
TrackerDataUpdateBufferResource *resource,
@@ -851,10 +828,6 @@ tracker_data_resource_buffer_flush (TrackerData *data,
return;
}
- if (table->class) {
- add_class_count (data, table->class, -1);
- }
-
/* remove row from class table */
stmt = tracker_db_interface_create_statement (iface,
TRACKER_DB_STATEMENT_CACHE_TYPE_UPDATE, &actual_error,
"DELETE FROM \"%s\".\"%s\"
WHERE ID = ?",
@@ -1090,24 +1063,6 @@ tracker_data_update_buffer_clear (TrackerData *data)
#if HAVE_TRACKER_FTS
data->update_buffer.fts_ever_updated = FALSE;
#endif
-
- if (data->update_buffer.class_counts) {
- /* revert class count changes */
-
- GHashTableIter iter;
- TrackerClass *class;
- gpointer count_ptr;
-
- g_hash_table_iter_init (&iter, data->update_buffer.class_counts);
- while (g_hash_table_iter_next (&iter, (gpointer*) &class, &count_ptr)) {
- gint count;
-
- count = GPOINTER_TO_INT (count_ptr);
- tracker_class_set_count (class, tracker_class_get_count (class) - count);
- }
-
- g_hash_table_remove_all (data->update_buffer.class_counts);
- }
}
static void
@@ -1150,8 +1105,6 @@ cache_create_service_decomposed (TrackerData *data,
cache_insert_value (data, "rdfs:Resource_rdf:type", "rdf:type",
&gvalue, TRUE, FALSE, FALSE);
- add_class_count (data, cl, 1);
-
if (data->insert_callbacks) {
guint n;
@@ -2084,8 +2037,6 @@ cache_delete_resource_type_full (TrackerData *data,
error = NULL;
}
}
-
- add_class_count (data, class, -1);
} else {
cache_delete_row (data, class);
}
@@ -2995,12 +2946,6 @@ tracker_data_commit_transaction (TrackerData *data,
data->in_transaction = FALSE;
data->in_ontology_transaction = FALSE;
- if (data->update_buffer.class_counts) {
- /* successful transaction, no need to rollback class counts,
- so remove them */
- g_hash_table_remove_all (data->update_buffer.class_counts);
- }
-
#if HAVE_TRACKER_FTS
if (data->update_buffer.fts_ever_updated) {
data->update_buffer.fts_ever_updated = FALSE;
diff --git a/src/tracker-store/tracker-statistics.vala b/src/tracker-store/tracker-statistics.vala
index e7f9a010c..407412876 100644
--- a/src/tracker-store/tracker-statistics.vala
+++ b/src/tracker-store/tracker-statistics.vala
@@ -21,48 +21,46 @@
public class Tracker.Statistics : Object {
public const string PATH = "/org/freedesktop/Tracker1/Statistics";
- static bool initialized;
+ static GLib.HashTable<Tracker.Class, int> class_counts;
[DBus (signature = "aas")]
public new Variant get (BusName sender) throws GLib.Error {
var request = DBusRequest.begin (sender, "Statistics.Get");
var data_manager = Tracker.Main.get_data_manager ();
var ontologies = data_manager.get_ontologies ();
+ var iface = data_manager.get_db_interface ();
- if (!initialized) {
- var iface = data_manager.get_db_interface ();
+ class_counts = new HashTable<Tracker.Class, int> (direct_hash, direct_equal);
- 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);
+ 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 ();
- if (stat_cursor.next ()) {
- cl.count = (int) stat_cursor.get_integer (0);
- } else {
- warning ("Unable to query instance count for class %s",
cl.name);
- }
+ var stat_cursor = stmt.start_cursor ();
+ if (stat_cursor.next ()) {
+ class_counts.insert (cl, (int) stat_cursor.get_integer (0));
+ } else {
+ warning ("Unable to query instance count for class %s", cl.name);
}
}
-
- initialized = true;
}
var builder = new VariantBuilder ((VariantType) "aas");
foreach (var cl in ontologies.get_classes ()) {
- if (cl.count == 0) {
+ int count = class_counts.lookup (cl);
+ if (count == 0) {
/* skip classes without resources */
continue;
}
builder.open ((VariantType) "as");
builder.add ("s", cl.name);
- builder.add ("s", cl.count.to_string ());
+ builder.add ("s", count.to_string ());
builder.close ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]