Commit 21b2c7c8 authored by Carlos Garnacho's avatar Carlos Garnacho

Merge branch 'wip/carlosg/speed-track' into 'master'

Speed track

See merge request !281
parents 975c05da 31319253
Pipeline #224185 passed with stages
in 7 minutes and 5 seconds
......@@ -9,7 +9,7 @@ private_sources = [
'tracker-crawler.c',
'tracker-file-data-provider.c',
'tracker-file-notifier.c',
'tracker-file-system.c',
'tracker-lru.c',
'tracker-monitor.c',
'tracker-priority-queue.c',
'tracker-task-pool.c',
......
This diff is collapsed.
......@@ -45,41 +45,45 @@ typedef struct TrackerCrawler TrackerCrawler;
typedef struct TrackerCrawlerClass TrackerCrawlerClass;
typedef struct TrackerCrawlerPrivate TrackerCrawlerPrivate;
typedef enum {
TRACKER_CRAWLER_CHECK_FILE = 1 << 0,
TRACKER_CRAWLER_CHECK_DIRECTORY = 1 << 1,
TRACKER_CRAWLER_CHECK_CONTENT = 1 << 2,
} TrackerCrawlerCheckFlags;
typedef gboolean (*TrackerCrawlerCheckFunc) (TrackerCrawler *crawler,
TrackerCrawlerCheckFlags flags,
GFile *file,
GFileInfo *file_info,
const GList *children,
gpointer user_data);
struct TrackerCrawler {
GObject parent;
};
struct TrackerCrawlerClass {
GObjectClass parent;
gboolean (* check_directory) (TrackerCrawler *crawler,
GFile *file);
gboolean (* check_file) (TrackerCrawler *crawler,
GFile *file);
gboolean (* check_directory_contents) (TrackerCrawler *crawler,
GFile *file,
GList *contents);
void (* directory_crawled) (TrackerCrawler *crawler,
GFile *directory,
GNode *tree,
guint directories_found,
guint directories_ignored,
guint files_found,
guint files_ignored);
void (* finished) (TrackerCrawler *crawler,
gboolean interrupted);
};
GType tracker_crawler_get_type (void);
TrackerCrawler *tracker_crawler_new (TrackerDataProvider *data_provider);
gboolean tracker_crawler_start (TrackerCrawler *crawler,
GFile *file,
TrackerDirectoryFlags flags);
void tracker_crawler_stop (TrackerCrawler *crawler);
void tracker_crawler_pause (TrackerCrawler *crawler);
void tracker_crawler_resume (TrackerCrawler *crawler);
void tracker_crawler_set_throttle (TrackerCrawler *crawler,
gdouble throttle);
gboolean tracker_crawler_get_finish (TrackerCrawler *crawler,
GAsyncResult *result,
GFile **directory,
GNode **tree,
guint *directories_found,
guint *directories_ignored,
guint *files_found,
guint *files_ignored,
GError **error);
void tracker_crawler_get (TrackerCrawler *crawler,
GFile *file,
TrackerDirectoryFlags flags,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
void tracker_crawler_set_file_attributes (TrackerCrawler *crawler,
const gchar *file_attributes);
......@@ -88,6 +92,11 @@ const gchar * tracker_crawler_get_file_attributes (TrackerCrawler *crawler);
GFileInfo * tracker_crawler_get_file_info (TrackerCrawler *crawler,
GFile *file);
void tracker_crawler_set_check_func (TrackerCrawler *crawler,
TrackerCrawlerCheckFunc func,
gpointer user_data,
GDestroyNotify destroy_notify);
G_END_DECLS
#endif /* __LIBTRACKER_MINER_CRAWLER_H__ */
......@@ -75,8 +75,6 @@ file_data_provider_begin (TrackerDataProvider *data_provider,
GError **error)
{
GFileQueryInfoFlags file_flags;
GFileEnumerator *fe;
GError *local_error = NULL;
if (g_cancellable_set_error_if_cancelled (cancellable, error)) {
return NULL;
......@@ -94,27 +92,11 @@ file_data_provider_begin (TrackerDataProvider *data_provider,
file_flags = G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS;
fe = g_file_enumerate_children (url,
attributes,
file_flags,
cancellable,
&local_error);
if (local_error) {
gchar *uri;
uri = g_file_get_uri (url);
g_warning ("Could not open directory '%s': %s",
uri, local_error->message);
g_propagate_error (error, local_error);
g_free (uri);
return NULL;
}
return fe;
return g_file_enumerate_children (url,
attributes,
file_flags,
cancellable,
error);
}
static void
......@@ -129,15 +111,6 @@ enumerate_children_cb (GObject *source_object,
enumerator = g_file_enumerate_children_finish (url, res, &error);
if (error) {
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
gchar *uri;
uri = g_file_get_uri (url);
g_warning ("Could not open directory '%s': %s",
uri, error->message);
g_free (uri);
}
g_task_return_error (task, error);
} else {
g_task_return_pointer (task, enumerator, (GDestroyNotify) g_object_unref);
......
......@@ -51,9 +51,11 @@ struct _TrackerFileNotifierClass {
GObjectClass parent_class;
void (* file_created) (TrackerFileNotifier *notifier,
GFile *file);
GFile *file,
GFileInfo *info);
void (* file_updated) (TrackerFileNotifier *notifier,
GFile *file,
GFileInfo *info,
gboolean attributes_only);
void (* file_deleted) (TrackerFileNotifier *notifier,
GFile *file);
......@@ -79,25 +81,13 @@ GType tracker_file_notifier_get_type (void) G_GNUC_CONST;
TrackerFileNotifier *
tracker_file_notifier_new (TrackerIndexingTree *indexing_tree,
TrackerDataProvider *data_provider,
TrackerSparqlConnection *connection);
TrackerSparqlConnection *connection,
const gchar *file_attributes);
gboolean tracker_file_notifier_start (TrackerFileNotifier *notifier);
void tracker_file_notifier_stop (TrackerFileNotifier *notifier);
gboolean tracker_file_notifier_is_active (TrackerFileNotifier *notifier);
const gchar * tracker_file_notifier_get_file_iri (TrackerFileNotifier *notifier,
GFile *file,
gboolean force);
void tracker_file_notifier_invalidate_file_iri (TrackerFileNotifier *notifier,
GFile *file,
gboolean recursive);
gboolean tracker_file_notifier_query_file_exists (TrackerFileNotifier *notifier,
GFile *file);
GFileType tracker_file_notifier_get_file_type (TrackerFileNotifier *notifier,
GFile *file);
G_END_DECLS
#endif /* __TRACKER_FILE_SYSTEM_H__ */
#endif /* __TRACKER_FILE_NOTIFIER_H__ */
This diff is collapsed.
/*
* Copyright (C) 2011, Nokia <ivan.frade@nokia.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* Author: Carlos Garnacho <carlos@lanedo.com>
*/
#ifndef __TRACKER_FILE_SYSTEM_H__
#define __TRACKER_FILE_SYSTEM_H__
#if !defined (__LIBTRACKER_MINER_H_INSIDE__) && !defined (TRACKER_COMPILATION)
#error "Only <libtracker-miner/tracker-miner.h> can be included directly."
#endif
#include <gio/gio.h>
G_BEGIN_DECLS
#define TRACKER_TYPE_FILE_SYSTEM (tracker_file_system_get_type())
#define TRACKER_FILE_SYSTEM(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), TRACKER_TYPE_FILE_SYSTEM, TrackerFileSystem))
#define TRACKER_FILE_SYSTEM_CLASS(c) (G_TYPE_CHECK_CLASS_CAST ((c), TRACKER_TYPE_FILE_SYSTEM, TrackerFileSystemClass))
#define TRACKER_IS_FILE_SYSTEM(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), TRACKER_TYPE_FILE_SYSTEM))
#define TRACKER_IS_FILE_SYSTEM_CLASS(c) (G_TYPE_CHECK_CLASS_TYPE ((c), TRACKER_TYPE_FILE_SYSTEM))
#define TRACKER_FILE_SYSTEM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), TRACKER_TYPE_FILE_SYSTEM, TrackerFileSystemClass))
typedef struct _TrackerFileSystem TrackerFileSystem;
typedef struct _TrackerFileSystemClass TrackerFileSystemClass;
struct _TrackerFileSystem {
GObject parent_instance;
};
struct _TrackerFileSystemClass {
GObjectClass parent_class;
};
typedef gboolean (* TrackerFileSystemTraverseFunc) (GFile *file,
gpointer user_data);
GType tracker_file_system_get_type (void) G_GNUC_CONST;
TrackerFileSystem *
tracker_file_system_new (GFile *root);
GFile * tracker_file_system_get_file (TrackerFileSystem *file_system,
GFile *file,
GFileType file_type,
GFile *parent);
GFile * tracker_file_system_peek_file (TrackerFileSystem *file_system,
GFile *file);
GFile * tracker_file_system_peek_parent (TrackerFileSystem *file_system,
GFile *file);
void tracker_file_system_traverse (TrackerFileSystem *file_system,
GFile *root,
GTraverseType order,
TrackerFileSystemTraverseFunc func,
gint max_depth,
gpointer user_data);
void tracker_file_system_forget_files (TrackerFileSystem *file_system,
GFile *root,
GFileType file_type);
GFileType tracker_file_system_get_file_type (TrackerFileSystem *file_system,
GFile *file);
/* properties */
void tracker_file_system_register_property (GQuark prop,
GDestroyNotify destroy_notify);
void tracker_file_system_set_property (TrackerFileSystem *file_system,
GFile *file,
GQuark prop,
gpointer prop_data);
gpointer tracker_file_system_get_property (TrackerFileSystem *file_system,
GFile *file,
GQuark prop);
void tracker_file_system_unset_property (TrackerFileSystem *file_system,
GFile *file,
GQuark prop);
gpointer tracker_file_system_steal_property (TrackerFileSystem *file_system,
GFile *file,
GQuark prop);
gboolean tracker_file_system_get_property_full (TrackerFileSystem *file_system,
GFile *file,
GQuark prop,
gpointer *data);
G_END_DECLS
#endif /* __TRACKER_FILE_SYSTEM_H__ */
......@@ -830,13 +830,13 @@ indexing_tree_file_is_filtered (TrackerIndexingTree *tree,
* tracker_indexing_tree_file_is_indexable:
* @tree: a #TrackerIndexingTree
* @file: a #GFile
* @file_type: a #GFileType
* @file_info: a #GFileInfo
*
* returns %TRUE if @file should be indexed according to the
* parameters given through tracker_indexing_tree_add() and
* tracker_indexing_tree_add_filter().
*
* If @file_type is #G_FILE_TYPE_UNKNOWN, file type will be queried to the
* If @file_info is %NULL, it will be queried to the
* file system.
*
* Returns: %TRUE if @file should be indexed.
......@@ -844,11 +844,12 @@ indexing_tree_file_is_filtered (TrackerIndexingTree *tree,
gboolean
tracker_indexing_tree_file_is_indexable (TrackerIndexingTree *tree,
GFile *file,
GFileType file_type)
GFileInfo *info)
{
TrackerFilterType filter;
TrackerDirectoryFlags config_flags;
GFile *config_file;
GFileType file_type;
g_return_val_if_fail (TRACKER_IS_INDEXING_TREE (tree), FALSE);
g_return_val_if_fail (G_IS_FILE (file), FALSE);
......@@ -859,28 +860,21 @@ tracker_indexing_tree_file_is_indexable (TrackerIndexingTree *tree,
return FALSE;
}
/* Don't check file type if _NO_STAT is given in flags */
if (file_type == G_FILE_TYPE_UNKNOWN &&
(config_flags & TRACKER_DIRECTORY_FLAG_NO_STAT) != 0) {
GFileQueryInfoFlags file_flags;
file_flags = G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS;
file_type = g_file_query_file_type (file, file_flags, NULL);
if (info == NULL) {
info = g_file_query_info (file,
G_FILE_ATTRIBUTE_STANDARD_TYPE ","
G_FILE_ATTRIBUTE_STANDARD_IS_HIDDEN,
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
NULL, NULL);
}
filter = (file_type == G_FILE_TYPE_DIRECTORY) ?
TRACKER_FILTER_DIRECTORY : TRACKER_FILTER_FILE;
file_type = info ? g_file_info_get_file_type (info) : G_FILE_TYPE_UNKNOWN;
if (indexing_tree_file_is_filtered (tree, filter, file)) {
return FALSE;
}
} else if (file_type != G_FILE_TYPE_UNKNOWN) {
filter = (file_type == G_FILE_TYPE_DIRECTORY) ?
TRACKER_FILTER_DIRECTORY : TRACKER_FILTER_FILE;
filter = (file_type == G_FILE_TYPE_DIRECTORY) ?
TRACKER_FILTER_DIRECTORY : TRACKER_FILTER_FILE;
if (indexing_tree_file_is_filtered (tree, filter, file)) {
return FALSE;
}
if (indexing_tree_file_is_filtered (tree, filter, file)) {
return FALSE;
}
/* FIXME: Shouldn't we only do this for file_type == G_FILE_TYPE_DIRECTORY ? */
......@@ -898,7 +892,7 @@ tracker_indexing_tree_file_is_indexable (TrackerIndexingTree *tree,
}
if (tracker_indexing_tree_get_filter_hidden (tree) &&
tracker_file_is_hidden (file)) {
info && g_file_info_get_is_hidden (info)) {
return FALSE;
}
......@@ -929,12 +923,6 @@ tracker_indexing_tree_parent_is_indexable (TrackerIndexingTree *tree,
priv = tree->priv;
if (!tracker_indexing_tree_file_is_indexable (tree,
parent,
G_FILE_TYPE_DIRECTORY)) {
return FALSE;
}
while (children && !has_match) {
has_match = tracker_indexing_tree_file_matches_filter (tree,
TRACKER_FILTER_PARENT_DIRECTORY,
......
......@@ -104,7 +104,7 @@ gboolean tracker_indexing_tree_file_matches_filter (TrackerIndexingTree *tree
gboolean tracker_indexing_tree_file_is_indexable (TrackerIndexingTree *tree,
GFile *file,
GFileType file_type);
GFileInfo *info);
gboolean tracker_indexing_tree_parent_is_indexable (TrackerIndexingTree *tree,
GFile *parent,
GList *children);
......
/*
* Copyright (C) 2020, Red Hat Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* Author: Carlos Garnacho <carlosg@gnome.org>
*/
#include "config-miners.h"
#include "tracker-lru.h"
typedef struct _TrackerLRUElement TrackerLRUElement;
struct _TrackerLRUElement {
gpointer element;
gpointer data;
GList *link;
};
struct _TrackerLRU {
GQueue queue;
GHashTable *items;
GDestroyNotify elem_destroy;
GDestroyNotify data_destroy;
guint max_size;
gint ref_count;
};
static void
free_node (TrackerLRUElement *node,
TrackerLRU *lru)
{
g_hash_table_remove (lru->items, node->element);
lru->elem_destroy (node->element);
lru->data_destroy (node->data);
g_slice_free (TrackerLRUElement, node);
}
TrackerLRU *
tracker_lru_new (guint size,
GHashFunc elem_hash_func,
GEqualFunc elem_equal_func,
GDestroyNotify elem_destroy,
GDestroyNotify data_destroy)
{
TrackerLRU *lru;
lru = g_new0 (TrackerLRU, 1);
g_queue_init (&lru->queue);
lru->max_size = size;
lru->elem_destroy = elem_destroy;
lru->data_destroy = data_destroy;
lru->items = g_hash_table_new (elem_hash_func,
elem_equal_func);
lru->ref_count = 1;
return lru;
}
TrackerLRU *
tracker_lru_ref (TrackerLRU *lru)
{
g_atomic_int_inc (&lru->ref_count);
return lru;
}
void
tracker_lru_unref (TrackerLRU *lru)
{
if (g_atomic_int_dec_and_test (&lru->ref_count)) {
TrackerLRUElement *node;
GHashTableIter iter;
g_hash_table_iter_init (&iter, lru->items);
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &node)) {
g_hash_table_iter_remove (&iter);
free_node (node, lru);
}
g_hash_table_unref (lru->items);
g_queue_clear (&lru->queue);
g_free (lru);
}
}
gboolean
tracker_lru_find (TrackerLRU *lru,
gpointer elem,
gpointer *data)
{
TrackerLRUElement *node;
node = g_hash_table_lookup (lru->items, elem);
if (!node)
return FALSE;
if (data)
*data = node->data;
if (node->link != lru->queue.head) {
/* Push to head */
g_queue_unlink (&lru->queue, node->link);
g_queue_push_head_link (&lru->queue, node->link);
}
return TRUE;
}
void
tracker_lru_add (TrackerLRU *lru,
gpointer elem,
gpointer data)
{
TrackerLRUElement *node, *last;
node = g_slice_new0 (TrackerLRUElement);
node->element = elem;
node->data = data;
node->link = g_list_alloc ();
node->link->data = node;
g_queue_push_head_link (&lru->queue, node->link);
g_hash_table_insert (lru->items, elem, node);
if (g_hash_table_size (lru->items) > lru->max_size) {
/* Remove last element */
last = g_queue_pop_tail (&lru->queue);
free_node (last, lru);
}
}
void
tracker_lru_remove (TrackerLRU *lru,
gpointer elem)
{
TrackerLRUElement *node;
node = g_hash_table_lookup (lru->items, elem);
if (!node)
return;
g_queue_remove (&lru->queue, node->link);
free_node (node, lru);
}
void
tracker_lru_remove_foreach (TrackerLRU *lru,
GEqualFunc equal_func,
gpointer elem)
{
TrackerLRUElement *node;
GList *next, *link = lru->queue.head;
while (link) {
node = link->data;
next = link->next;
if (equal_func (node->element, elem) == TRUE) {
g_queue_unlink (&lru->queue, node->link);
free_node (node, lru);
}
link = next;
}
}
/*
* Copyright (C) 2020, Red Hat Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* Author: Carlos Garnacho <carlosg@gnome.org>
*/
#ifndef __TRACKER_LRU_H__
#define __TRACKER_LRU_H__
#include <glib.h>
typedef struct _TrackerLRU TrackerLRU;
TrackerLRU * tracker_lru_new (guint size,
GHashFunc elem_hash_func,
GEqualFunc elem_equal_func,
GDestroyNotify elem_destroy,
GDestroyNotify data_destroy);
TrackerLRU *tracker_lru_ref (TrackerLRU *lru);
void tracker_lru_unref (TrackerLRU *lru);
gboolean tracker_lru_find (TrackerLRU *lru,
gpointer elem,
gpointer *data);
void tracker_lru_add (TrackerLRU *lru,
gpointer elem