tracker r1348 - in branches/indexer-split: . src/trackerd



Author: mr
Date: Mon May  5 13:46:03 2008
New Revision: 1348
URL: http://svn.gnome.org/viewvc/tracker?rev=1348&view=rev

Log:
	* src/trackerd/tracker-utils.[ch]:
	* src/trackerd/tracker-db-sqlite.c: Removed tracker_timer_start()
	and tracker_timer_end() since they are only used in one place.
	Used a GTimer instead of GTimeVal and also optimised the loading
	of the prepared queries by using the GMappedFile API.


Modified:
   branches/indexer-split/ChangeLog
   branches/indexer-split/src/trackerd/tracker-db-sqlite.c
   branches/indexer-split/src/trackerd/tracker-utils.c
   branches/indexer-split/src/trackerd/tracker-utils.h

Modified: branches/indexer-split/src/trackerd/tracker-db-sqlite.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-db-sqlite.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-db-sqlite.c	Mon May  5 13:46:03 2008
@@ -311,70 +311,85 @@
 gboolean
 tracker_db_initialize (void)
 {
-	FILE	 *file;
-	char	 *sql_file;
-	GTimeVal *tv;
-	int i = 0;
-
-	prepared_queries = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
+	GTimer      *t;
+	GError      *error = NULL;
+	GMappedFile *mapped_file;
+	GStrv        queries;
+	gchar       *sql_filename;
+	gdouble      secs;
 
 	tracker_log ("Loading prepared queries...");
 
-	sql_file = g_build_filename (SHAREDIR, "tracker", "sqlite-stored-procs.sql", NULL);
-
-	if (!g_file_test (sql_file, G_FILE_TEST_EXISTS)) {
-		tracker_error ("ERROR: Tracker cannot read required file %s - Please reinstall tracker or check read permissions on the file if it exists", sql_file);
-		g_assert (FALSE);
-	}
+	prepared_queries = g_hash_table_new_full (g_str_hash, 
+						  g_str_equal, 
+						  g_free, 
+						  g_free);
 
+	sql_filename = g_build_filename (SHAREDIR, 
+					 "tracker", 
+					 "sqlite-stored-procs.sql", 
+					 NULL);
 
-	file = g_fopen (sql_file, "r");
-	
+	t = g_timer_new ();
 
-	tv = tracker_timer_start ();
+	mapped_file = g_mapped_file_new (sql_filename, FALSE, &error);
 
-	while (!feof (file)) {
-		char buffer[8192];
-		char *sep;
+	if (error || !mapped_file) {
+		tracker_debug ("Could not get contents of SQL file:'%s', %s",
+			       sql_filename,
+			       error ? error->message : "no error given");
 
-		i++;
+		if (mapped_file) {
+			g_mapped_file_free (mapped_file);
+		}
 
-		if (!fgets (buffer, 8192, file)) {
-                  /* An "if" to avoid warnings about value returned by fgets()
-                     not handled...
-                     We do not look the returned value since we will have NULL
-                     with a file which terminates with '\n' on a empty line...
-                  */
-                }
+		g_timer_destroy (t);
+		g_free (sql_filename);
 
-		if (strlen (buffer) < 5) {
-			continue;
-		}
+		return FALSE;
+	}
 
-		sep = strchr (buffer, ' ');
+	tracker_debug ("Opened prepared queries file:'%s' size:%" G_GSIZE_FORMAT " bytes", 
+		       sql_filename,
+		       g_mapped_file_get_length (mapped_file));
 
-		if (sep) {
-			const char *query, *name;
+	queries = g_strsplit (g_mapped_file_get_contents (mapped_file), "\n", -1);
+	g_free (sql_filename);
 
-			*sep = '\0';
+	if (queries) {
+		GStrv p;
 
-			query = sep + 1;
-			name = buffer;
+		for (p = queries; *p; p++) {
+			GStrv details;
 
-			//tracker_log ("installing query %s with sql %s", name, query);
-			g_hash_table_insert (prepared_queries, g_strdup (name), g_strdup (query));
-		} else {
-			continue;
-		}
+			details = g_strsplit (*p, " ", 2); 
+			
+			if (!details) {
+				continue;
+			}
 
+			if (!details[0] || !details[1]) {
+				continue;
+			}
 
-	}
+			tracker_debug ("  Adding query:'%s'", details[0]);
 
-	fclose (file);
+			g_hash_table_insert (prepared_queries, 
+					     g_strdup (details[0]), 
+					     g_strdup (details[1]));
+			g_strfreev (details);
+		}
 
-	g_free (sql_file);
+		g_strfreev (queries);
+	}
 
-	tracker_timer_end (tv, "File loaded in ");
+	secs = g_timer_elapsed (t, NULL);
+	g_timer_destroy (t);
+	g_mapped_file_free (mapped_file);
+	
+	tracker_log ("Found %d prepared queries in %4.4f seconds", 
+		     g_hash_table_size (prepared_queries), 
+		     secs);
 
 	return TRUE;
 }

Modified: branches/indexer-split/src/trackerd/tracker-utils.c
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-utils.c	(original)
+++ branches/indexer-split/src/trackerd/tracker-utils.c	Mon May  5 13:46:03 2008
@@ -451,35 +451,6 @@
 	}
 }
 
-GTimeVal *
-tracker_timer_start (void)
-{
-	GTimeVal  *before;
-
-	before = g_new0 (GTimeVal, 1);
-
-	g_get_current_time (before);
-
-	return before;
-}
-
-
-void
-tracker_timer_end (GTimeVal *before, const char *str)
-{
-	GTimeVal  after;
-	double	  elapsed;
-
-	g_get_current_time (&after);
-
-	elapsed = (1000 * (after.tv_sec - before->tv_sec))  +  ((after.tv_usec - before->tv_usec) / 1000.0);
-
-	g_free (before);
-
-	tracker_log ("%s %f ms", str, elapsed);
-}
-
-
 char *
 tracker_compress (const char *ptr, int size, int *compressed_size)
 {

Modified: branches/indexer-split/src/trackerd/tracker-utils.h
==============================================================================
--- branches/indexer-split/src/trackerd/tracker-utils.h	(original)
+++ branches/indexer-split/src/trackerd/tracker-utils.h	Mon May  5 13:46:03 2008
@@ -155,7 +155,7 @@
 
 	gboolean	readonly;
 
-	int		pid;
+	int		pid; 
 
 	gpointer	hal;
 
@@ -331,9 +331,6 @@
 void		tracker_notify_meta_data_available 	(void);
 void		tracker_notify_request_data_available 	(void);
 
-GTimeVal *	tracker_timer_start 		(void);
-void		tracker_timer_end 		(GTimeVal *before, const char *str);
-
 char *		tracker_compress 		(const char *ptr, int size, int *compressed_size);
 char *		tracker_uncompress 		(const char *ptr, int size, int *uncompressed_size);
 



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