[tracker/miner-fs-refactor: 6/110] libtracker-miner: avoid extra file type checks
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/miner-fs-refactor: 6/110] libtracker-miner: avoid extra file type checks
- Date: Wed, 2 Nov 2011 12:28:32 +0000 (UTC)
commit d4b20882ffea79e81022017fb49f44d643d206a1
Author: Aleksander Morgado <aleksander lanedo com>
Date: Wed Aug 3 11:18:49 2011 +0200
libtracker-miner: avoid extra file type checks
src/libtracker-miner/tracker-indexing-tree.c | 21 ++++++++----
src/libtracker-miner/tracker-indexing-tree.h | 3 +-
src/libtracker-miner/tracker-monitor.c | 45 ++++++++++++++++++-------
3 files changed, 48 insertions(+), 21 deletions(-)
---
diff --git a/src/libtracker-miner/tracker-indexing-tree.c b/src/libtracker-miner/tracker-indexing-tree.c
index 1901441..791a76c 100644
--- a/src/libtracker-miner/tracker-indexing-tree.c
+++ b/src/libtracker-miner/tracker-indexing-tree.c
@@ -432,20 +432,24 @@ parent_or_equals (GFile *file1,
* tracker_indexing_tree_file_is_indexable:
* @tree: a #TrackerIndexingTree
* @file: a #GFile
+ * @file_type: a #GFileType
*
* returns %TRUE if @file should be indexed according to the
* parameters given through tracker_indexing_tree_add() and
- * tracker_indexing_tree_add_filter()
+ * tracker_indexing_tree_add_filter().
+ *
+ * If @file_type is #G_FILE_TYPE_UNKNOWN, file type will be queried to the
+ * file system.
*
* Returns: %TRUE if @file should be indexed.
**/
gboolean
tracker_indexing_tree_file_is_indexable (TrackerIndexingTree *tree,
- GFile *file)
+ GFile *file,
+ GFileType file_type)
{
TrackerIndexingTreePrivate *priv;
TrackerFilterType filter;
- GFileType file_type;
NodeData *data;
GNode *parent;
@@ -454,9 +458,10 @@ tracker_indexing_tree_file_is_indexable (TrackerIndexingTree *tree,
priv = tree->priv;
- file_type = g_file_query_file_type (file,
- G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
- NULL);
+ if (file_type == G_FILE_TYPE_UNKNOWN)
+ file_type = g_file_query_file_type (file,
+ G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
+ NULL);
filter = (file_type == G_FILE_TYPE_DIRECTORY) ?
TRACKER_FILTER_DIRECTORY : TRACKER_FILTER_FILE;
@@ -501,7 +506,9 @@ tracker_indexing_tree_parent_is_indexable (TrackerIndexingTree *tree,
{
gint i = 0;
- if (!tracker_indexing_tree_file_is_indexable (tree, parent)) {
+ if (!tracker_indexing_tree_file_is_indexable (tree,
+ parent,
+ G_FILE_TYPE_DIRECTORY)) {
return FALSE;
}
diff --git a/src/libtracker-miner/tracker-indexing-tree.h b/src/libtracker-miner/tracker-indexing-tree.h
index def7c57..b57b4e8 100644
--- a/src/libtracker-miner/tracker-indexing-tree.h
+++ b/src/libtracker-miner/tracker-indexing-tree.h
@@ -72,7 +72,8 @@ gboolean tracker_indexing_tree_file_matches_filter (TrackerIndexingTree *tree
GFile *file);
gboolean tracker_indexing_tree_file_is_indexable (TrackerIndexingTree *tree,
- GFile *file);
+ GFile *file,
+ GFileType file_type);
gboolean tracker_indexing_tree_parent_is_indexable (TrackerIndexingTree *tree,
GFile *parent,
GFile **children,
diff --git a/src/libtracker-miner/tracker-monitor.c b/src/libtracker-miner/tracker-monitor.c
index 0719ded..2a18165 100644
--- a/src/libtracker-miner/tracker-monitor.c
+++ b/src/libtracker-miner/tracker-monitor.c
@@ -699,9 +699,13 @@ emit_signal_for_event (TrackerMonitor *monitor,
event_data->file);
}
+ /* Try to avoid firing up events for ignored files */
if (monitor->priv->tree &&
!tracker_indexing_tree_file_is_indexable (monitor->priv->tree,
- event_data->file)) {
+ event_data->file,
+ (event_data->is_directory ?
+ G_FILE_TYPE_DIRECTORY :
+ G_FILE_TYPE_REGULAR))) {
g_debug ("Emitting ITEM_UPDATED for %s (%s) from "
"a move event, source is not indexable",
event_data->other_file_uri,
@@ -712,7 +716,10 @@ emit_signal_for_event (TrackerMonitor *monitor,
event_data->is_directory);
} else if (monitor->priv->tree &&
!tracker_indexing_tree_file_is_indexable (monitor->priv->tree,
- event_data->other_file)) {
+ event_data->other_file,
+ (event_data->is_directory ?
+ G_FILE_TYPE_DIRECTORY :
+ G_FILE_TYPE_REGULAR))) {
g_debug ("Emitting ITEM_DELETED for %s (%s) from "
"a move event, destination is not indexable",
event_data->file_uri,
@@ -726,7 +733,6 @@ emit_signal_for_event (TrackerMonitor *monitor,
event_data->is_directory ? "DIRECTORY" : "FILE",
event_data->file_uri,
event_data->other_file_uri);
-
g_signal_emit (monitor,
signals[ITEM_MOVED], 0,
event_data->file,
@@ -1207,27 +1213,45 @@ monitor_event_cb (GFileMonitor *file_monitor,
file_uri = g_file_get_uri (file);
if (!other_file) {
+ is_directory = check_is_directory (monitor, file);
+
/* Avoid non-indexable-files */
if (monitor->priv->tree &&
!tracker_indexing_tree_file_is_indexable (monitor->priv->tree,
- file)) {
+ file,
+ (is_directory ?
+ G_FILE_TYPE_DIRECTORY :
+ G_FILE_TYPE_REGULAR))) {
g_free (file_uri);
return;
}
other_file_uri = NULL;
- g_debug ("Received monitor event:%d (%s) for file:'%s'",
+ g_debug ("Received monitor event:%d (%s) for %s:'%s'",
event_type,
monitor_event_to_string (event_type),
+ is_directory ? "directory" : "file",
file_uri);
- is_directory = check_is_directory (monitor, file);
} else {
+ /* If we have other_file, it means an item was moved from file to other_file;
+ * so, it makes sense to check if the other_file is directory instead of
+ * the origin file, as this one will not exist any more */
+ is_directory = check_is_directory (monitor, other_file);
+
/* Avoid doing anything of both
* file/other_file are non-indexable
*/
if (monitor->priv->tree &&
- !tracker_indexing_tree_file_is_indexable (monitor->priv->tree, file) &&
- !tracker_indexing_tree_file_is_indexable (monitor->priv->tree, other_file)) {
+ !tracker_indexing_tree_file_is_indexable (monitor->priv->tree,
+ file,
+ (is_directory ?
+ G_FILE_TYPE_DIRECTORY :
+ G_FILE_TYPE_REGULAR)) &&
+ !tracker_indexing_tree_file_is_indexable (monitor->priv->tree,
+ other_file,
+ (is_directory ?
+ G_FILE_TYPE_DIRECTORY :
+ G_FILE_TYPE_REGULAR))) {
g_free (file_uri);
return;
}
@@ -1238,11 +1262,6 @@ monitor_event_cb (GFileMonitor *file_monitor,
monitor_event_to_string (event_type),
file_uri,
other_file_uri);
-
- /* If we have other_file, it means an item was moved from file to other_file;
- * so, it makes sense to check if the other_file is directory instead of
- * the origin file, as this one will not exist any more */
- is_directory = check_is_directory (monitor, other_file);
}
#ifdef PAUSE_ON_IO
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]