tracker r1610 - in branches/indexer-split: . data src/libtracker-db
- From: carlosg svn gnome org
- To: svn-commits-list gnome org
- Subject: tracker r1610 - in branches/indexer-split: . data src/libtracker-db
- Date: Mon, 9 Jun 2008 15:17:46 +0000 (UTC)
Author: carlosg
Date: Mon Jun 9 15:17:46 2008
New Revision: 1610
URL: http://svn.gnome.org/viewvc/tracker?rev=1610&view=rev
Log:
2008-06-09 Carlos Garnacho <carlos imendio com>
* src/libtracker-db/tracker-db-manager.c (function_compress_string)
(function_compress): Added, database function to compress a passed
string using zlib.
(db_interface_get_file_contents) (db_interface_get_email_contents):
Create that function for these database connections.
* data/sqlite-stored-procs.sql (SaveServiceContents): Use compress(),
so the indexer code doesn't have to compress the contents itself.
Modified:
branches/indexer-split/ChangeLog
branches/indexer-split/data/sqlite-stored-procs.sql
branches/indexer-split/src/libtracker-db/tracker-db-manager.c
Modified: branches/indexer-split/data/sqlite-stored-procs.sql
==============================================================================
--- branches/indexer-split/data/sqlite-stored-procs.sql (original)
+++ branches/indexer-split/data/sqlite-stored-procs.sql Mon Jun 9 15:17:46 2008
@@ -81,7 +81,7 @@
GetByServiceType SELECT DISTINCT F.Path || '/' || F.Name as uri FROM Services F WHERE F.ServiceTypeID in (select TypeId from common.ServiceTypes where TypeName = ? or Parent = ?) LIMIT ?,?;
-SaveServiceContents REPLACE into ServiceContents (ServiceID, MetadataID, Content) values (?,?,?);
+SaveServiceContents REPLACE into ServiceContents (ServiceID, MetadataID, Content) values (?,?,compress (?));
DeleteContent DELETE FROM ServiceContents where ServiceID = ? and MetadataId = ?;
DeleteAllContents DELETE FROM ServiceContents where ServiceID = ?;
GetContents Select uncompress (Content) from ServiceContents where ServiceID = ? and MetadataID = ? and Content is not null;
Modified: branches/indexer-split/src/libtracker-db/tracker-db-manager.c
==============================================================================
--- branches/indexer-split/src/libtracker-db/tracker-db-manager.c (original)
+++ branches/indexer-split/src/libtracker-db/tracker-db-manager.c Mon Jun 9 15:17:46 2008
@@ -1192,6 +1192,97 @@
return buf;
}
+static GByteArray *
+function_compress_string (const gchar *text)
+{
+ GByteArray *array;
+ z_stream zs;
+ gchar *buf, *swap;
+ guchar obuf[ZLIBBUFSIZ];
+ gint rv, asiz, bsiz, osiz, size;
+
+ size = strlen (text);
+
+ zs.zalloc = Z_NULL;
+ zs.zfree = Z_NULL;
+ zs.opaque = Z_NULL;
+
+ if (deflateInit2 (&zs, 6, Z_DEFLATED, 15, 6, Z_DEFAULT_STRATEGY) != Z_OK) {
+ return NULL;
+ }
+
+ asiz = size + 16;
+
+ if (asiz < ZLIBBUFSIZ) {
+ asiz = ZLIBBUFSIZ;
+ }
+
+ if (!(buf = malloc (asiz))) {
+ deflateEnd (&zs);
+ return NULL;
+ }
+
+ bsiz = 0;
+ zs.next_in = (unsigned char *) text;
+ zs.avail_in = size;
+ zs.next_out = obuf;
+ zs.avail_out = ZLIBBUFSIZ;
+
+ while ((rv = deflate (&zs, Z_FINISH)) == Z_OK) {
+ osiz = ZLIBBUFSIZ - zs.avail_out;
+
+ if (bsiz + osiz > asiz) {
+ asiz = asiz * 2 + osiz;
+
+ if (!(swap = realloc (buf, asiz))) {
+ free (buf);
+ deflateEnd (&zs);
+ return NULL;
+ }
+
+ buf = swap;
+ }
+
+ memcpy (buf + bsiz, obuf, osiz);
+ bsiz += osiz;
+ zs.next_out = obuf;
+ zs.avail_out = ZLIBBUFSIZ;
+ }
+
+ if (rv != Z_STREAM_END) {
+ free (buf);
+ deflateEnd (&zs);
+ return NULL;
+ }
+
+ osiz = ZLIBBUFSIZ - zs.avail_out;
+
+ if (bsiz + osiz + 1 > asiz) {
+ asiz = asiz * 2 + osiz;
+
+ if (!(swap = realloc (buf, asiz))) {
+ free (buf);
+ deflateEnd (&zs);
+ return NULL;
+ }
+
+ buf = swap;
+ }
+
+ memcpy (buf + bsiz, obuf, osiz);
+ bsiz += osiz;
+ buf[bsiz] = '\0';
+
+ array = g_byte_array_new ();
+ g_byte_array_append (array, (const guint8 *) buf, bsiz);
+
+ g_free (buf);
+
+ deflateEnd (&zs);
+
+ return array;
+}
+
static GValue
function_uncompress (TrackerDBInterface *interface,
gint argc,
@@ -1223,6 +1314,30 @@
return result;
}
+static GValue
+function_compress (TrackerDBInterface *interface,
+ gint argc,
+ GValue values[])
+{
+ GByteArray *array;
+ GValue result = { 0, };
+ const gchar *text;
+
+ text = g_value_get_string (&values[0]);
+
+ array = function_compress_string (text);
+
+ if (!array) {
+ g_warning ("Compress failed");
+ return result;
+ }
+
+ g_value_init (&result, TRACKER_TYPE_DB_BLOB);
+ g_value_take_boxed (&result, array);
+
+ return result;
+}
+
static void
db_set_params (TrackerDBInterface *iface,
gint cache_size,
@@ -1537,7 +1652,10 @@
"uncompress",
function_uncompress,
1);
-
+ tracker_db_interface_sqlite_create_function (iface,
+ "compress",
+ function_compress,
+ 1);
return iface;
}
@@ -1582,7 +1700,10 @@
"uncompress",
function_uncompress,
1);
-
+ tracker_db_interface_sqlite_create_function (iface,
+ "compress",
+ function_compress,
+ 1);
return iface;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]