[tracker/wip/carlosg/sparql1.1: 93/145] libtracker-data: Convert to GValues earlier in tracker_data_*_statement()
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/wip/carlosg/sparql1.1: 93/145] libtracker-data: Convert to GValues earlier in tracker_data_*_statement()
- Date: Thu, 18 Jul 2019 22:31:51 +0000 (UTC)
commit 89dc666bbf71490f6bb06ef09378f36e74993808
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Jun 16 15:33:40 2019 +0200
libtracker-data: Convert to GValues earlier in tracker_data_*_statement()
We insist on keeping string values (or IDs as ints) to the deepest points,
in some cases even transforming GValues back to strings, in order to
transform them back to GValues.
Use GValue more integrally in data updates, keeps things simpler and does
not require this transformation back and forth.
src/libtracker-data/tracker-data-update.c | 225 +++++++++++-------------------
1 file changed, 84 insertions(+), 141 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-update.c b/src/libtracker-data/tracker-data-update.c
index 7ff0ff882..9230cf6ee 100644
--- a/src/libtracker-data/tracker-data-update.c
+++ b/src/libtracker-data/tracker-data-update.c
@@ -180,12 +180,9 @@ static void cache_insert_value (TrackerData *data,
static GArray *get_old_property_values (TrackerData *data,
TrackerProperty *property,
GError **error);
-static gchar* gvalue_to_string (TrackerPropertyType type,
- GValue *gvalue);
static gboolean delete_metadata_decomposed (TrackerData *data,
TrackerProperty *property,
- const gchar *value,
- gint value_id,
+ GValue *gvalue,
GError **error);
static void resource_buffer_switch (TrackerData *data,
const gchar *graph,
@@ -1289,7 +1286,6 @@ cache_create_service_decomposed (TrackerData *data,
if (old_values &&
old_values->len > 0) {
GValue *v;
- GValue gvalue_copy = { 0 };
/* Don't expect several values for property which is a domain index */
g_assert_cmpint (old_values->len, ==, 1);
@@ -1300,13 +1296,11 @@ cache_create_service_decomposed (TrackerData *data,
tracker_class_get_name (cl));
v = &g_array_index (old_values, GValue, 0);
- g_value_init (&gvalue_copy, G_VALUE_TYPE (v));
- g_value_copy (v, &gvalue_copy);
cache_insert_value (data,
tracker_class_get_name (cl),
tracker_property_get_name (*domain_indexes),
- &gvalue_copy,
+ v,
tracker_property_get_multiple_values (*domain_indexes),
tracker_property_get_fulltext_indexed (*domain_indexes),
tracker_property_get_data_type (*domain_indexes) ==
TRACKER_PROPERTY_TYPE_DATETIME);
@@ -1619,49 +1613,6 @@ string_to_gvalue (const gchar *value,
}
}
-static gchar*
-gvalue_to_string (TrackerPropertyType type,
- GValue *gvalue)
-{
- gchar *retval = NULL;
- gint64 datet;
- gint offset;
-
- switch (type) {
- case TRACKER_PROPERTY_TYPE_STRING:
- retval = g_value_dup_string (gvalue);
- break;
- case TRACKER_PROPERTY_TYPE_INTEGER:
- retval = g_strdup_printf ("%" G_GINT64_FORMAT, g_value_get_int64 (gvalue));
- break;
- case TRACKER_PROPERTY_TYPE_BOOLEAN:
- retval = g_value_get_int64 (gvalue) == 0 ? g_strdup ("false") : g_strdup ("true");
- break;
- case TRACKER_PROPERTY_TYPE_DOUBLE:
- retval = g_new0 (char, G_ASCII_DTOSTR_BUF_SIZE);
- g_ascii_dtostr (retval, G_ASCII_DTOSTR_BUF_SIZE,
- g_value_get_double (gvalue));
- break;
- case TRACKER_PROPERTY_TYPE_DATE:
- datet = g_value_get_int64 (gvalue);
- retval = tracker_date_to_string (datet, 0);
- /* it's a date-only, cut off the time */
- retval[10] = '\0';
- break;
- case TRACKER_PROPERTY_TYPE_DATETIME:
- datet = tracker_date_time_get_time (gvalue);
- offset = tracker_date_time_get_offset (gvalue);
- retval = tracker_date_to_string (datet, offset);
- break;
- case TRACKER_PROPERTY_TYPE_RESOURCE:
- default:
- g_warn_if_reached ();
- break;
- }
-
- return retval;
-}
-
static gboolean
resource_in_domain_index_class (TrackerData *data,
TrackerClass *domain_index_class)
@@ -1686,15 +1637,10 @@ process_domain_indexes (TrackerData *data,
domain_index_classes = tracker_property_get_domain_indexes (property);
while (*domain_index_classes) {
if (resource_in_domain_index_class (data, *domain_index_classes)) {
- GValue gvalue_copy = { 0 };
-
- g_value_init (&gvalue_copy, G_VALUE_TYPE (gvalue));
- g_value_copy (gvalue, &gvalue_copy);
-
cache_insert_value (data,
tracker_class_get_name (*domain_index_classes),
field_name,
- &gvalue_copy,
+ gvalue,
FALSE,
tracker_property_get_fulltext_indexed (property),
tracker_property_get_data_type (property) ==
TRACKER_PROPERTY_TYPE_DATETIME);
@@ -1706,15 +1652,13 @@ process_domain_indexes (TrackerData *data,
static gboolean
cache_insert_metadata_decomposed (TrackerData *data,
TrackerProperty *property,
- const gchar *value,
- gint value_id,
+ GValue *value,
GError **error)
{
gboolean multiple_values;
const gchar *table_name;
const gchar *field_name;
TrackerProperty **super_properties;
- GValue gvalue = { 0 };
GArray *old_values;
GError *new_error = NULL;
gboolean change = FALSE;
@@ -1736,7 +1680,7 @@ cache_insert_metadata_decomposed (TrackerData *data,
super_is_multi = tracker_property_get_multiple_values (*super_properties);
if (super_is_multi || old_values->len == 0) {
- change |= cache_insert_metadata_decomposed (data, *super_properties, value, value_id,
+ change |= cache_insert_metadata_decomposed (data, *super_properties, value,
&new_error);
if (new_error) {
g_propagate_error (error, new_error);
@@ -1749,20 +1693,8 @@ cache_insert_metadata_decomposed (TrackerData *data,
table_name = tracker_property_get_table_name (property);
field_name = tracker_property_get_name (property);
- if (value) {
- string_to_gvalue (value, tracker_property_get_data_type (property), &gvalue, data,
&new_error);
- if (new_error) {
- g_propagate_error (error, new_error);
- return FALSE;
- }
- } else {
- g_value_init (&gvalue, G_TYPE_INT64);
- g_value_set_int64 (&gvalue, value_id);
- }
-
- if (!value_set_add_value (old_values, &gvalue)) {
+ if (!value_set_add_value (old_values, value)) {
/* value already inserted */
- g_value_unset (&gvalue);
} else if (!multiple_values && old_values->len > 1) {
/* trying to add second value to single valued property */
GValue old_value = { 0 };
@@ -1798,17 +1730,15 @@ cache_insert_metadata_decomposed (TrackerData *data,
g_free (new_value_str);
g_value_unset (&old_value);
g_value_unset (&new_value);
- g_value_unset (&gvalue);
-
} else {
cache_insert_value (data, table_name, field_name,
- &gvalue,
+ value,
multiple_values,
tracker_property_get_fulltext_indexed (property),
tracker_property_get_data_type (property) ==
TRACKER_PROPERTY_TYPE_DATETIME);
if (!multiple_values) {
- process_domain_indexes (data, property, &gvalue, field_name);
+ process_domain_indexes (data, property, value, field_name);
}
change = TRUE;
@@ -1835,29 +1765,32 @@ delete_first_object (TrackerData *data,
if (tracker_property_get_data_type (field) == TRACKER_PROPERTY_TYPE_RESOURCE) {
GError *new_error = NULL;
- GValue *v;
+ GValue *v, copy = G_VALUE_INIT;
v = &g_array_index (old_values, GValue, 0);
- object_id = (gint) g_value_get_int64 (v);
+ g_value_init (©, G_VALUE_TYPE (v));
+ g_value_copy (v, ©);
/* This influences old_values, which is a reference, not a copy */
- change = delete_metadata_decomposed (data, field, NULL, object_id, &new_error);
+ change = delete_metadata_decomposed (data, field, ©, &new_error);
+ g_value_unset (©);
if (new_error) {
g_propagate_error (error, new_error);
return change;
}
} else {
- GValue *v;
+ GValue *v, copy = G_VALUE_INIT;
GError *new_error = NULL;
- gchar *object_str = NULL;
object_id = 0;
v = &g_array_index (old_values, GValue, 0);
- object_str = gvalue_to_string (tracker_property_get_data_type (field), v);
+ g_value_init (©, G_VALUE_TYPE (v));
+ g_value_copy (v, ©);
/* This influences old_values, which is a reference, not a copy */
- change = delete_metadata_decomposed (data, field, object_str, 0, &new_error);
+ change = delete_metadata_decomposed (data, field, ©, &new_error);
+ g_value_unset (©);
if (new_error) {
g_propagate_error (error, new_error);
@@ -1875,13 +1808,11 @@ delete_first_object (TrackerData *data,
data->resource_buffer->id,
data->resource_buffer->subject,
pred_id, object_id,
- object_str,
+ g_value_get_string (v),
data->resource_buffer->types,
delegate->user_data);
}
}
-
- g_free (object_str);
}
return change;
@@ -1890,8 +1821,7 @@ delete_first_object (TrackerData *data,
static gboolean
cache_update_metadata_decomposed (TrackerData *data,
TrackerProperty *property,
- const gchar *value,
- gint value_id,
+ GValue *value,
const gchar *graph,
GError **error)
{
@@ -1899,7 +1829,6 @@ cache_update_metadata_decomposed (TrackerData *data,
const gchar *table_name;
const gchar *field_name;
TrackerProperty **super_properties;
- GValue gvalue = { 0 };
GError *new_error = NULL;
gboolean change = FALSE;
@@ -1951,7 +1880,7 @@ cache_update_metadata_decomposed (TrackerData *data,
g_free (subject);
}
- change |= cache_update_metadata_decomposed (data, *super_properties, value, value_id,
+ change |= cache_update_metadata_decomposed (data, *super_properties, value,
graph, &new_error);
if (new_error) {
g_propagate_error (error, new_error);
@@ -1963,25 +1892,14 @@ cache_update_metadata_decomposed (TrackerData *data,
table_name = tracker_property_get_table_name (property);
field_name = tracker_property_get_name (property);
- if (value) {
- string_to_gvalue (value, tracker_property_get_data_type (property), &gvalue, data,
&new_error);
- if (new_error) {
- g_propagate_error (error, new_error);
- return FALSE;
- }
- } else {
- g_value_init (&gvalue, G_TYPE_INT64);
- g_value_set_int64 (&gvalue, value_id);
- }
-
cache_insert_value (data, table_name, field_name,
- &gvalue,
+ value,
multiple_values,
tracker_property_get_fulltext_indexed (property),
tracker_property_get_data_type (property) == TRACKER_PROPERTY_TYPE_DATETIME);
if (!multiple_values) {
- process_domain_indexes (data, property, &gvalue, field_name);
+ process_domain_indexes (data, property, value, field_name);
}
return TRUE;
@@ -1990,15 +1908,13 @@ cache_update_metadata_decomposed (TrackerData *data,
static gboolean
delete_metadata_decomposed (TrackerData *data,
TrackerProperty *property,
- const gchar *value,
- gint value_id,
+ GValue *value,
GError **error)
{
gboolean multiple_values;
const gchar *table_name;
const gchar *field_name;
TrackerProperty **super_properties;
- GValue gvalue = { 0 };
GArray *old_values;
GError *new_error = NULL;
gboolean change = FALSE;
@@ -2015,23 +1931,11 @@ delete_metadata_decomposed (TrackerData *data,
return FALSE;
}
- if (value) {
- string_to_gvalue (value, tracker_property_get_data_type (property), &gvalue, data,
&new_error);
- if (new_error) {
- g_propagate_error (error, new_error);
- return FALSE;
- }
- } else {
- g_value_init (&gvalue, G_TYPE_INT64);
- g_value_set_int64 (&gvalue, value_id);
- }
-
- if (!value_set_remove_value (old_values, &gvalue)) {
+ if (!value_set_remove_value (old_values, value)) {
/* value not found */
- g_value_unset (&gvalue);
} else {
cache_delete_value (data, table_name, field_name,
- &gvalue, multiple_values,
+ value, multiple_values,
tracker_property_get_fulltext_indexed (property),
tracker_property_get_data_type (property) ==
TRACKER_PROPERTY_TYPE_DATETIME);
@@ -2042,13 +1946,10 @@ delete_metadata_decomposed (TrackerData *data,
while (*domain_index_classes) {
if (resource_in_domain_index_class (data, *domain_index_classes)) {
- GValue gvalue_copy = { 0 };
- g_value_init (&gvalue_copy, G_VALUE_TYPE (&gvalue));
- g_value_copy (&gvalue, &gvalue_copy);
cache_delete_value (data,
tracker_class_get_name (*domain_index_classes),
field_name,
- &gvalue_copy, multiple_values,
+ value, multiple_values,
tracker_property_get_fulltext_indexed (property),
tracker_property_get_data_type (property) ==
TRACKER_PROPERTY_TYPE_DATETIME);
}
@@ -2062,7 +1963,7 @@ delete_metadata_decomposed (TrackerData *data,
/* also delete super property values */
super_properties = tracker_property_get_super_properties (property);
while (*super_properties) {
- change |= delete_metadata_decomposed (data, *super_properties, value, value_id, error);
+ change |= delete_metadata_decomposed (data, *super_properties, value, error);
super_properties++;
}
@@ -2219,15 +2120,12 @@ cache_delete_resource_type_full (TrackerData *data,
for (y = old_values->len - 1; y >= 0 ; y--) {
GValue *old_gvalue;
- GValue gvalue = { 0 };
old_gvalue = &g_array_index (old_values, GValue, y);
- g_value_init (&gvalue, G_VALUE_TYPE (old_gvalue));
- g_value_copy (old_gvalue, &gvalue);
- value_set_remove_value (old_values, &gvalue);
+ value_set_remove_value (old_values, old_gvalue);
cache_delete_value (data, table_name, field_name,
- &gvalue, multiple_values,
+ old_gvalue, multiple_values,
tracker_property_get_fulltext_indexed (prop),
tracker_property_get_data_type (prop) ==
TRACKER_PROPERTY_TYPE_DATETIME);
@@ -2238,13 +2136,10 @@ cache_delete_resource_type_full (TrackerData *data,
domain_index_classes = tracker_property_get_domain_indexes (prop);
while (*domain_index_classes) {
if (resource_in_domain_index_class (data, *domain_index_classes)) {
- GValue gvalue_copy = { 0 };
- g_value_init (&gvalue_copy, G_VALUE_TYPE (&gvalue));
- g_value_copy (&gvalue, &gvalue_copy);
cache_delete_value (data,
tracker_class_get_name
(*domain_index_classes),
field_name,
- &gvalue_copy, multiple_values,
+ old_gvalue, multiple_values,
tracker_property_get_fulltext_indexed
(prop),
tracker_property_get_data_type (prop) ==
TRACKER_PROPERTY_TYPE_DATETIME);
}
@@ -2447,9 +2342,20 @@ tracker_data_delete_statement (TrackerData *data,
field = tracker_ontologies_get_property_by_uri (ontologies, predicate);
if (field != NULL) {
+ GError *inner_error = NULL;
+ GValue object_value = G_VALUE_INIT;
+
pred_id = tracker_property_get_id (field);
data->has_persistent = TRUE;
- change = delete_metadata_decomposed (data, field, object, 0, error);
+
+ string_to_gvalue (object, tracker_property_get_data_type (field), &object_value,
data, &inner_error);
+ if (inner_error) {
+ g_propagate_error (error, inner_error);
+ return;
+ }
+
+ change = delete_metadata_decomposed (data, field, &object_value, error);
+ g_value_unset (&object_value);
} else {
g_set_error (error, TRACKER_SPARQL_ERROR, TRACKER_SPARQL_ERROR_UNKNOWN_PROPERTY,
"Property '%s' not found in the ontology", predicate);
@@ -2741,8 +2647,18 @@ tracker_data_insert_statement_with_uri (TrackerData *data,
change = TRUE;
} else {
+ GValue object_value = G_VALUE_INIT;
+
+ string_to_gvalue (object, tracker_property_get_data_type (property), &object_value, data,
&actual_error);
+ if (actual_error) {
+ g_propagate_error (error, actual_error);
+ return;
+ }
+
/* add value to metadata database */
- change = cache_insert_metadata_decomposed (data, property, object, 0, &actual_error);
+ change = cache_insert_metadata_decomposed (data, property, &object_value, &actual_error);
+ g_value_unset (&object_value);
+
if (actual_error) {
g_propagate_error (error, actual_error);
return;
@@ -2783,6 +2699,7 @@ tracker_data_insert_statement_with_string (TrackerData *data,
gint graph_id = 0, pred_id = 0;
TrackerOntologies *ontologies;
TrackerDBInterface *iface;
+ GValue object_value = G_VALUE_INIT;
g_return_if_fail (subject != NULL);
g_return_if_fail (predicate != NULL);
@@ -2820,8 +2737,16 @@ tracker_data_insert_statement_with_string (TrackerData *data,
if (graph)
graph_id = tracker_data_manager_find_graph (data->manager, graph);
+ string_to_gvalue (object, tracker_property_get_data_type (property), &object_value, data,
&actual_error);
+ if (actual_error) {
+ g_propagate_error (error, actual_error);
+ return;
+ }
+
/* add value to metadata database */
- change = cache_insert_metadata_decomposed (data, property, object, 0, &actual_error);
+ change = cache_insert_metadata_decomposed (data, property, &object_value, &actual_error);
+ g_value_unset (&object_value);
+
if (actual_error) {
g_propagate_error (error, actual_error);
return;
@@ -2933,6 +2858,7 @@ tracker_data_update_statement_with_uri (TrackerData *data,
gboolean multiple_values;
GError *new_error = NULL;
gboolean domain_unchecked = TRUE;
+ GValue object_value = G_VALUE_INIT;
multiple_values = tracker_property_get_multiple_values (property);
@@ -2996,8 +2922,16 @@ tracker_data_update_statement_with_uri (TrackerData *data,
return;
}
+ string_to_gvalue (object, tracker_property_get_data_type (property), &object_value, data,
&new_error);
+ if (new_error) {
+ g_propagate_error (error, new_error);
+ return;
+ }
+
/* update or add value to metadata database */
- change = cache_update_metadata_decomposed (data, property, object, 0, graph, &actual_error);
+ change = cache_update_metadata_decomposed (data, property, &object_value, graph,
&actual_error);
+ g_value_unset (&object_value);
+
if (actual_error) {
g_propagate_error (error, actual_error);
return;
@@ -3056,6 +2990,7 @@ tracker_data_update_statement_with_string (TrackerData *data,
gboolean multiple_values;
TrackerOntologies *ontologies;
TrackerDBInterface *iface;
+ GValue object_value = G_VALUE_INIT;
#if HAVE_TRACKER_FTS
GError *new_error = NULL;
#endif /* HAVE_TRACKER_FTS */
@@ -3113,8 +3048,16 @@ tracker_data_update_statement_with_string (TrackerData *data,
}
#endif /* HAVE_TRACKER_FTS */
+ string_to_gvalue (object, tracker_property_get_data_type (property), &object_value, data, &new_error);
+ if (new_error) {
+ g_propagate_error (error, new_error);
+ return;
+ }
+
/* add or update value to metadata database */
- change = cache_update_metadata_decomposed (data, property, object, 0, graph, &actual_error);
+ change = cache_update_metadata_decomposed (data, property, &object_value, graph, &actual_error);
+ g_value_unset (&object_value);
+
if (actual_error) {
g_propagate_error (error, actual_error);
return;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]