[tracker/wip/carlosg/domain-ontologies: 51/55] libtracker-fts: Remove tracker_fts_init/shutdown functions



commit 4d921aed03ab1c47b6e4c635af3e1dbd52c39ac2
Author: Carlos Garnacho <carlosg gnome org>
Date:   Sat Jun 10 00:12:46 2017 +0200

    libtracker-fts: Remove tracker_fts_init/shutdown functions
    
    Instead, load the FTS extension in every TrackerDBInterface manually.

 src/libtracker-data/tracker-data-manager.c        |   13 -----
 src/libtracker-data/tracker-db-interface-sqlite.c |    1 +
 src/libtracker-fts/tracker-fts-tokenizer.c        |   23 +++++----
 src/libtracker-fts/tracker-fts.c                  |   53 ++-------------------
 src/libtracker-fts/tracker-fts.h                  |    2 -
 5 files changed, 18 insertions(+), 74 deletions(-)
---
diff --git a/src/libtracker-data/tracker-data-manager.c b/src/libtracker-data/tracker-data-manager.c
index 89a8bbd..4ffcccd 100644
--- a/src/libtracker-data/tracker-data-manager.c
+++ b/src/libtracker-data/tracker-data-manager.c
@@ -3742,12 +3742,6 @@ tracker_data_manager_init (TrackerDBManagerFlags   flags,
        read_only = (flags & TRACKER_DB_MANAGER_READONLY) ? TRUE : FALSE;
        data_update = tracker_data_new ();
 
-#if HAVE_TRACKER_FTS
-       if (!tracker_fts_init ()) {
-               g_warning ("FTS module initialization failed");
-       }
-#endif
-
        /* First set defaults for return values */
        if (first_time) {
                *first_time = FALSE;
@@ -4658,13 +4652,6 @@ tracker_data_manager_shutdown (void)
 
        g_clear_pointer (&db_manager, tracker_db_manager_free);
        g_clear_object (&ontologies);
-
-#if HAVE_TRACKER_FTS
-       if (!tracker_fts_shutdown ()) {
-               g_warning ("FTS module shutdown failed");
-       }
-#endif
-
        g_clear_object (&data_update);
 
        initialized = FALSE;
diff --git a/src/libtracker-data/tracker-db-interface-sqlite.c 
b/src/libtracker-data/tracker-db-interface-sqlite.c
index 7fd4b0c..f22957f 100644
--- a/src/libtracker-data/tracker-db-interface-sqlite.c
+++ b/src/libtracker-data/tracker-db-interface-sqlite.c
@@ -1490,6 +1490,7 @@ open_database (TrackerDBInterface  *db_interface,
 
        sqlite3_extended_result_codes (db_interface->db, 0);
        sqlite3_busy_timeout (db_interface->db, 100000);
+       sqlite3_db_config (db_interface->db, SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION, 1, NULL);
 }
 
 static gboolean
diff --git a/src/libtracker-fts/tracker-fts-tokenizer.c b/src/libtracker-fts/tracker-fts-tokenizer.c
index e3db10c..fed3c7e 100644
--- a/src/libtracker-fts/tracker-fts-tokenizer.c
+++ b/src/libtracker-fts/tracker-fts-tokenizer.c
@@ -205,10 +205,10 @@ tracker_offsets_function (const Fts5ExtensionApi  *api,
                           int                      n_args,
                           sqlite3_value          **args)
 {
+       TrackerTokenizerFunctionData *data;
        GString *str;
        int rc, n_hits, i;
        GArray *offsets = NULL;
-       const gchar * const *property_names;
        gint cur_col = -1;
        gboolean first = TRUE;
 
@@ -217,7 +217,7 @@ tracker_offsets_function (const Fts5ExtensionApi  *api,
                return;
        }
 
-       property_names = api->xUserData (fts_ctx);
+       data = api->xUserData (fts_ctx);
        rc = api->xInstCount (fts_ctx, &n_hits);
 
        if (rc != SQLITE_OK) {
@@ -255,7 +255,7 @@ tracker_offsets_function (const Fts5ExtensionApi  *api,
                        break;
 
                g_string_append_printf (str, "%s,%d",
-                                       property_names[col],
+                                       data->property_names[col],
                                        g_array_index (offsets, gint, n_token));
        }
 
@@ -272,7 +272,7 @@ tracker_offsets_function (const Fts5ExtensionApi  *api,
 }
 
 static GHashTable *
-get_fts_weights (sqlite3_context *context)
+get_fts_weights (sqlite3_context    *context)
 {
        static GHashTable *weights = NULL;
        static GMutex mutex;
@@ -334,7 +334,7 @@ tracker_rank_function (const Fts5ExtensionApi  *api,
                        int                      n_args,
                        sqlite3_value          **args)
 {
-       const gchar * const *property_names;
+       TrackerTokenizerFunctionData *data;
        int i, rc, n_columns, n_tokens;
        GHashTable *weights;
        gdouble rank = 0;
@@ -345,7 +345,7 @@ tracker_rank_function (const Fts5ExtensionApi  *api,
        }
 
        n_columns = api->xColumnCount (fts_ctx);
-       property_names = api->xUserData (fts_ctx);
+       data = api->xUserData (fts_ctx);
        weights = get_fts_weights (ctx);
 
        if (!weights) {
@@ -364,7 +364,7 @@ tracker_rank_function (const Fts5ExtensionApi  *api,
                if (n_tokens <= 0)
                        continue;
 
-               property = property_names[i];
+               property = data->property_names[i];
                weight = GPOINTER_TO_UINT (g_hash_table_lookup (weights, property));
                rank += weight;
        }
@@ -396,21 +396,22 @@ get_fts5_api (sqlite3 *db) {
        return api;
 }
 
-TrackerTokenizerFunctionData *
+static TrackerTokenizerFunctionData *
 tracker_tokenizer_function_data_new (TrackerDBInterface  *interface,
                                      const gchar        **property_names)
 {
        TrackerTokenizerFunctionData *data;
 
        data = g_new0 (TrackerTokenizerFunctionData, 1);
-       data->interface = g_object_ref (interface);
-       data->property_names = g_strdupv (property_names);
+       data->interface = interface;
+       data->property_names = g_strdupv ((gchar **) property_names);
+
+       return data;
 }
 
 static void
 tracker_tokenizer_function_data_free (TrackerTokenizerFunctionData *data)
 {
-       g_object_unref (data->interface);
        g_strfreev (data->property_names);
        g_free (data);
 }
diff --git a/src/libtracker-fts/tracker-fts.c b/src/libtracker-fts/tracker-fts.c
index ec5ac29..b3c8645 100644
--- a/src/libtracker-fts/tracker-fts.c
+++ b/src/libtracker-fts/tracker-fts.c
@@ -31,53 +31,10 @@
 #include "sqlite3.h"
 #include "fts5.h"
 
-static gsize      module_initialized = 0;
-
 int sqlite3_fts5_init ();
 
 #endif
 
-static gboolean   initialized = FALSE;
-
-
-gboolean
-tracker_fts_init (void)
-{
-       if (initialized) {
-               return TRUE;
-       }
-
-#ifdef HAVE_BUILTIN_FTS
-       initialized = TRUE;
-
-       /* SQLite has all needed FTS5 features compiled in */
-       return TRUE;
-#else
-       int rc = SQLITE_OK;
-
-       if (g_once_init_enter (&module_initialized)) {
-               rc = sqlite3_auto_extension ((void (*) (void)) sqlite3_fts5_init);
-               g_once_init_leave (&module_initialized, (rc == SQLITE_OK));
-       }
-
-       initialized = module_initialized != 0;
-
-       return initialized;
-#endif
-}
-
-gboolean
-tracker_fts_shutdown (void)
-{
-       if (!initialized) {
-               return TRUE;
-       }
-
-       initialized = FALSE;
-
-       return TRUE;
-}
-
 static gchar **
 get_fts_properties (GHashTable  *tables)
 {
@@ -105,8 +62,12 @@ tracker_fts_init_db (sqlite3            *db,
 {
        gchar **property_names;
        gboolean retval;
+       gchar *err;
 
-       g_return_val_if_fail (initialized == TRUE, FALSE);
+       if (sqlite3_load_extension (db, NULL, "sqlite3_fts5_init", &err) != SQLITE_OK) {
+               g_warning ("Could not load fts5 module: %s", err);
+               return FALSE;
+       }
 
        property_names = get_fts_properties (tables);
        retval = tracker_tokenizer_initialize (db, interface, (const gchar **) property_names);
@@ -127,8 +88,6 @@ tracker_fts_create_table (sqlite3    *db,
        GList *columns;
        gint rc;
 
-       g_return_val_if_fail (initialized == TRUE, FALSE);
-
        if (g_hash_table_size (tables) == 0)
                return TRUE;
 
@@ -205,8 +164,6 @@ tracker_fts_alter_table (sqlite3    *db,
        gchar *query, *tmp_name;
        int rc;
 
-       g_return_val_if_fail (initialized == TRUE, FALSE);
-
        tmp_name = g_strdup_printf ("%s_TMP", table_name);
 
        query = g_strdup_printf ("DROP VIEW fts_view");
diff --git a/src/libtracker-fts/tracker-fts.h b/src/libtracker-fts/tracker-fts.h
index e1461f1..751014f 100644
--- a/src/libtracker-fts/tracker-fts.h
+++ b/src/libtracker-fts/tracker-fts.h
@@ -29,8 +29,6 @@
 
 G_BEGIN_DECLS
 
-gboolean    tracker_fts_init             (void);
-gboolean    tracker_fts_shutdown         (void);
 gboolean    tracker_fts_init_db          (sqlite3            *db,
                                           TrackerDBInterface *interface,
                                           GHashTable         *tables);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]