[tracker-miners/wip/carlosg/batches-and-resources: 27/31] tracker-miner-fs: Optimize insertion of new folders
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/wip/carlosg/batches-and-resources: 27/31] tracker-miner-fs: Optimize insertion of new folders
- Date: Fri, 11 Dec 2020 10:55:04 +0000 (UTC)
commit 46032d3aa834db160996d96153911e9e27335405
Author: Carlos Garnacho <carlosg gnome org>
Date: Thu Dec 3 17:34:01 2020 +0100
tracker-miner-fs: Optimize insertion of new folders
If a folder is being newly inserted, we don't need to check the resource
ID in the database first, and can resort on the blank node label generation
paths.
This avoids needless selects when inserting new folders.
src/libtracker-miner/tracker-miner-fs.c | 52 +++++++++++++++++++--------------
src/libtracker-miner/tracker-miner-fs.h | 1 +
src/miners/fs/tracker-miner-files.c | 14 +++++----
3 files changed, 39 insertions(+), 28 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-miner-fs.c b/src/libtracker-miner/tracker-miner-fs.c
index 36955b21c..7d3c43c6c 100644
--- a/src/libtracker-miner/tracker-miner-fs.c
+++ b/src/libtracker-miner/tracker-miner-fs.c
@@ -2364,45 +2364,53 @@ tracker_miner_fs_get_data_provider (TrackerMinerFS *fs)
static gchar *
tracker_miner_fs_get_file_bnode (TrackerMinerFS *fs,
GFile *file,
- gboolean create)
+ gboolean in_batch)
{
+ gchar *uri, *bnode, *checksum;
+
g_return_val_if_fail (TRACKER_IS_MINER_FS (fs), NULL);
g_return_val_if_fail (G_IS_FILE (file), NULL);
- if (create ||
- tracker_task_pool_find (fs->priv->task_pool, file) ||
- tracker_sparql_buffer_get_state (fs->priv->sparql_buffer, file) == TRACKER_BUFFER_STATE_QUEUED) {
- gchar *uri, *bnode, *checksum;
-
- uri = g_file_get_uri (file);
- checksum = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, -1);
- bnode = g_strdup_printf ("_:%s", checksum);
- g_free (checksum);
- g_free (uri);
-
- return bnode;
- }
+ uri = g_file_get_uri (file);
+ checksum = g_compute_checksum_for_string (G_CHECKSUM_MD5, uri, -1);
+ bnode = g_strdup_printf ("_:%s", checksum);
+ g_free (checksum);
+ g_free (uri);
- return NULL;
+ return bnode;
}
gchar *
tracker_miner_fs_get_identifier (TrackerMinerFS *miner,
GFile *file,
gboolean new_resource,
+ gboolean check_batch,
gboolean *is_iri)
{
- const gchar *urn;
+ TrackerMinerFSPrivate *priv = miner->priv;
+ gboolean in_batch = FALSE;
if (is_iri)
*is_iri = FALSE;
- urn = tracker_miner_fs_get_folder_urn (miner, file);
- if (urn) {
- if (is_iri)
- *is_iri = TRUE;
- return g_strdup (urn);
+ if (!new_resource && check_batch) {
+ in_batch = (tracker_task_pool_find (priv->task_pool, file) ||
+ tracker_sparql_buffer_get_state (priv->sparql_buffer, file) ==
TRACKER_BUFFER_STATE_QUEUED);
}
- return tracker_miner_fs_get_file_bnode (miner, file, new_resource);
+ if (new_resource || in_batch) {
+ return tracker_miner_fs_get_file_bnode (miner, file, in_batch);
+ } else {
+ const gchar *urn = NULL;
+
+ urn = tracker_miner_fs_get_folder_urn (miner, file);
+
+ if (urn) {
+ if (is_iri)
+ *is_iri = TRUE;
+ return g_strdup (urn);
+ }
+
+ return g_strdup (urn);
+ }
}
diff --git a/src/libtracker-miner/tracker-miner-fs.h b/src/libtracker-miner/tracker-miner-fs.h
index 691ffe1fd..de165157b 100644
--- a/src/libtracker-miner/tracker-miner-fs.h
+++ b/src/libtracker-miner/tracker-miner-fs.h
@@ -167,6 +167,7 @@ void tracker_miner_fs_notify_finish (TrackerMinerFS *f
gchar * tracker_miner_fs_get_identifier (TrackerMinerFS *miner,
GFile *file,
gboolean new_resource,
+ gboolean check_batch,
gboolean *is_iri);
/* Progress */
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index 1a76bba2c..8b55c0251 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -1978,7 +1978,7 @@ miner_files_add_to_datasource (TrackerMinerFiles *mf,
root = tracker_indexing_tree_get_root (indexing_tree, file, NULL);
if (root)
- identifier = tracker_miner_fs_get_identifier (fs, root, FALSE, NULL);
+ identifier = tracker_miner_fs_get_identifier (fs, root, FALSE, TRUE, NULL);
if (identifier)
tracker_resource_set_uri (resource, "nie:dataSource", identifier);
@@ -2011,7 +2011,8 @@ miner_files_add_mount_info (TrackerMinerFiles *miner,
static TrackerResource *
miner_files_create_folder_information_element (TrackerMinerFiles *miner,
GFile *file,
- const gchar *mime_type)
+ const gchar *mime_type,
+ gboolean create)
{
TrackerResource *resource, *file_resource;
TrackerIndexingTree *indexing_tree;
@@ -2019,7 +2020,7 @@ miner_files_create_folder_information_element (TrackerMinerFiles *miner,
/* Preserve URN for nfo:Folders */
urn = tracker_miner_fs_get_identifier (TRACKER_MINER_FS (miner),
- file, TRUE, NULL);
+ file, create, TRUE, NULL);
resource = tracker_resource_new (urn);
g_free (urn);
@@ -2105,7 +2106,7 @@ miner_files_process_file (TrackerMinerFS *fs,
tracker_resource_add_uri (resource, "rdf:type", "nfo:FileDataObject");
parent = g_file_get_parent (file);
- parent_urn = tracker_miner_fs_get_identifier (fs, parent, FALSE, NULL);
+ parent_urn = tracker_miner_fs_get_identifier (fs, parent, FALSE, TRUE, NULL);
g_object_unref (parent);
if (parent_urn) {
@@ -2135,7 +2136,8 @@ miner_files_process_file (TrackerMinerFS *fs,
folder_resource =
miner_files_create_folder_information_element (TRACKER_MINER_FILES (fs),
file,
- mime_type);
+ mime_type,
+ create);
}
miner_files_add_to_datasource (TRACKER_MINER_FILES (fs), file, resource, folder_resource);
@@ -2314,7 +2316,7 @@ miner_files_move_file (TrackerMinerFS *fs,
gchar *new_parent_id;
gboolean is_iri;
- new_parent_id = tracker_miner_fs_get_identifier (fs, new_parent, FALSE, &is_iri);
+ new_parent_id = tracker_miner_fs_get_identifier (fs, new_parent, FALSE, FALSE, &is_iri);
if (new_parent_id) {
container_clause =
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]