[tracker-miners/wip/carlosg/delay-monitors: 17/19] tracker-miner-fs: Repurpose crawling-interval setting
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker-miners/wip/carlosg/delay-monitors: 17/19] tracker-miner-fs: Repurpose crawling-interval setting
- Date: Sun, 8 Nov 2020 21:07:06 +0000 (UTC)
commit aae3d53d5e862b3823fbbb3158c1ae173fa6cec9
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Nov 8 20:37:58 2020 +0100
tracker-miner-fs: Repurpose crawling-interval setting
This setting (in days) was used to check whether tracker-miner-fs
would crawl on startup, after checking a timestamp file. However, we
are making crawling good and fast, and we don't like outdated databases.
Make this setting set up a timeout for long-running sessions instead,
and always perform crawling on startup.
src/miners/fs/tracker-main.c | 56 +----------------
src/miners/fs/tracker-miner-files.c | 121 ++++++++++--------------------------
src/miners/fs/tracker-miner-files.h | 4 --
3 files changed, 35 insertions(+), 146 deletions(-)
---
diff --git a/src/miners/fs/tracker-main.c b/src/miners/fs/tracker-main.c
index c4574c2fd..03041685b 100644
--- a/src/miners/fs/tracker-main.c
+++ b/src/miners/fs/tracker-main.c
@@ -52,8 +52,6 @@
"\n" \
" http://www.gnu.org/licenses/gpl.txt\n"
-#define SECONDS_PER_DAY 60 * 60 * 24
-
#define DBUS_NAME_SUFFIX "Tracker3.Miner.Files"
#define DBUS_PATH "/org/freedesktop/Tracker3/Miner/Files"
#define LOCALE_FILENAME "locale-for-miner-apps.txt"
@@ -68,7 +66,6 @@ static gboolean no_daemon;
static gchar *eligible;
static gboolean version;
static guint miners_timeout_id = 0;
-static gboolean do_crawling = FALSE;
static gchar *domain_ontology_name = NULL;
static gboolean dry_run = FALSE;
@@ -327,46 +324,6 @@ initialize_priority_and_scheduling (void)
}
}
-static gboolean
-should_crawl (TrackerMinerFiles *miner_files,
- TrackerConfig *config)
-{
- gint crawling_interval;
-
- crawling_interval = tracker_config_get_crawling_interval (config);
-
- TRACKER_NOTE (CONFIG, g_message ("Checking whether to crawl file system based on configured crawling
interval:"));
-
- if (crawling_interval == -2) {
- TRACKER_NOTE (CONFIG, g_message (" Disabled"));
- return FALSE;
- } else if (crawling_interval == -1) {
- TRACKER_NOTE (CONFIG, g_message (" Maybe (depends on a clean last shutdown)"));
- return TRUE;
- } else if (crawling_interval == 0) {
- TRACKER_NOTE (CONFIG, g_message (" Forced"));
- return TRUE;
- } else {
- guint64 then, now;
-
- then = tracker_miner_files_get_last_crawl_done (miner_files);
-
- if (then < 1) {
- return TRUE;
- }
-
- now = (guint64) time (NULL);
-
- if (now < then + (crawling_interval * SECONDS_PER_DAY)) {
- TRACKER_NOTE (CONFIG, g_message (" Postponed"));
- return FALSE;
- } else {
- TRACKER_NOTE (CONFIG, g_message (" (More than) %d days after last crawling,
enabled", crawling_interval));
- return TRUE;
- }
- }
-}
-
static void
miner_do_start (TrackerMiner *miner)
{
@@ -486,11 +443,6 @@ miner_finished_cb (TrackerMinerFS *fs,
total_directories_found,
total_files_found);
- if (do_crawling && !dry_run) {
- tracker_miner_files_set_last_crawl_done (TRACKER_MINER_FILES (fs),
- TRUE);
- }
-
cleanup_id = g_timeout_add_seconds (30, cleanup_cb, NULL);
/* We're not sticking around for file updates, so stop
@@ -1101,11 +1053,6 @@ main (gint argc, gchar *argv[])
g_free (dbus_name);
- /* Check if we should crawl and if we should force mtime
- * checking based on the config.
- */
- do_crawling = should_crawl (TRACKER_MINER_FILES (miner_files), config);
-
g_signal_connect (miner_files, "started",
G_CALLBACK (miner_started_cb),
NULL);
@@ -1128,8 +1075,7 @@ main (gint argc, gchar *argv[])
"CREATE SILENT GRAPH tracker:Video ",
NULL, graphs_created_cb, miner_files);
- if (do_crawling)
- miner_start (miner_files, config);
+ miner_start (miner_files, config);
initialize_signal_handler ();
diff --git a/src/miners/fs/tracker-miner-files.c b/src/miners/fs/tracker-miner-files.c
index f8df81340..f0c69e820 100644
--- a/src/miners/fs/tracker-miner-files.c
+++ b/src/miners/fs/tracker-miner-files.c
@@ -50,7 +50,6 @@
/* Stamp files to know crawling/indexing state */
#define FIRST_INDEX_FILENAME "first-index.txt"
-#define LAST_CRAWL_FILENAME "last-crawl.txt"
#define DEFAULT_GRAPH "tracker:FileSystem"
@@ -96,6 +95,7 @@ struct TrackerMinerFilesPrivate {
GDBusConnection *connection;
guint force_recheck_id;
+ guint crawl_interval_id;
gboolean index_removable_devices;
gboolean index_optical_discs;
@@ -765,6 +765,9 @@ miner_files_finalize (GObject *object)
priv->force_recheck_id = 0;
}
+ if (priv->crawl_interval_id != 0)
+ g_source_remove (priv->crawl_interval_id);
+
if (priv->stale_volumes_check_id) {
g_source_remove (priv->stale_volumes_check_id);
priv->stale_volumes_check_id = 0;
@@ -1704,6 +1707,33 @@ tracker_miner_files_trigger_check_delayed (TrackerMinerFiles *mf,
}
}
+static gboolean
+crawl_interval_idle (gpointer user_data)
+{
+ TrackerMinerFiles *miner_files = user_data;
+
+ tracker_miner_files_trigger_check (miner_files);
+
+ return G_SOURCE_CONTINUE;
+}
+
+static void
+tracker_miner_files_update_crawl_interval (TrackerMinerFiles *mf)
+{
+ guint interval;
+
+ if (mf->private->crawl_interval_id != 0)
+ g_source_remove (mf->private->crawl_interval_id);
+
+ interval = tracker_config_get_crawling_interval (mf->private->config);
+
+ if (interval > 0) {
+ mf->private->crawl_interval_id =
+ g_timeout_add_seconds (interval * SECONDS_PER_DAY,
+ crawl_interval_idle, mf);
+ }
+}
+
static void
trigger_recheck_cb (GObject *gobject,
GParamSpec *arg1,
@@ -2259,6 +2289,9 @@ miner_files_finished (TrackerMinerFS *fs,
* anything due to e.g. race conditions in crawling/monitoring.
*/
tracker_miner_files_trigger_check_delayed (mf, 5 * 60);
+
+ /* And also schedule a long-term period */
+ tracker_miner_files_update_crawl_interval (mf);
}
static gchar *
@@ -2732,89 +2765,3 @@ tracker_miner_files_set_first_index_done (TrackerMinerFiles *mf,
g_free (filename);
}
-
-static inline gchar *
-get_last_crawl_filename (TrackerMinerFiles *mf)
-{
- GFile *file;
- gchar *prefix, *path;
-
- file = get_cache_dir (mf);
- prefix = g_file_get_path (file);
-
- path = g_build_filename (prefix,
- LAST_CRAWL_FILENAME,
- NULL);
- g_free (prefix);
- g_object_unref (file);
-
- return path;
-}
-
-/**
- * tracker_miner_files_get_last_crawl_done:
- *
- * Check when last crawl was performed.
- *
- * Returns: time_t() value when last crawl occurred, otherwise 0.
- **/
-guint64
-tracker_miner_files_get_last_crawl_done (TrackerMinerFiles *mf)
-{
- gchar *filename;
- gchar *content;
- guint64 then;
-
- filename = get_last_crawl_filename (mf);
-
- if (!g_file_get_contents (filename, &content, NULL, NULL)) {
- g_info (" No previous timestamp, crawling forced");
- return 0;
- }
-
- then = g_ascii_strtoull (content, NULL, 10);
- g_free (content);
-
- return then;
-}
-
-/**
- * tracker_miner_files_set_last_crawl_done:
- *
- * Set the time stamp of the last full index of files.
- **/
-void
-tracker_miner_files_set_last_crawl_done (TrackerMinerFiles *mf,
- gboolean done)
-{
- gboolean already_exists;
- gchar *filename;
-
- filename = get_last_crawl_filename (mf);
- already_exists = g_file_test (filename, G_FILE_TEST_EXISTS);
-
- if (done) {
- GError *error = NULL;
- gchar *content;
- content = g_strdup_printf ("%" G_GUINT64_FORMAT, (guint64) time (NULL));
- if (already_exists) {
- g_info (" Overwriting last crawl file:'%s'", filename);
- } else {
- g_info (" Creating last crawl file:'%s'", filename);
- }
- /* Create/update time stamp file */
- if (!g_file_set_contents (filename, content, -1, &error)) {
- g_warning (" Could not create/overwrite file:'%s' failed, %s",
- filename,
- error->message);
- g_error_free (error);
- } else {
- g_info (" Last crawl file:'%s' updated", filename);
- }
-
- g_free (content);
- } else {
- g_info (" Crawl not done yet, doesn't update last crawl file.");
- }
- g_free (filename);
-}
diff --git a/src/miners/fs/tracker-miner-files.h b/src/miners/fs/tracker-miner-files.h
index 6053c9b10..16e8deb1e 100644
--- a/src/miners/fs/tracker-miner-files.h
+++ b/src/miners/fs/tracker-miner-files.h
@@ -58,10 +58,6 @@ gboolean tracker_miner_files_get_first_index_done (TrackerMinerFiles *mf);
void tracker_miner_files_set_first_index_done (TrackerMinerFiles *mf,
gboolean done);
-guint64 tracker_miner_files_get_last_crawl_done (TrackerMinerFiles *mf);
-void tracker_miner_files_set_last_crawl_done (TrackerMinerFiles *mf,
- gboolean done);
-
G_END_DECLS
#endif /* __TRACKER_MINER_FS_FILES_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]