Updating branch refs/heads/master to bfcaa3f9ddbe266b0f418506d64fe85fa68723fe (commit) from f70f44801a1fa182ea86b33323c35b6534a61f2a (commit)
commit bfcaa3f9ddbe266b0f418506d64fe85fa68723fe Author: Christian Dywan <christ...@twotoasts.de> Date: Fri Jul 1 03:32:11 2011 +0200 Index sender names in a separate table postler/postler-index.vala | 33 +++++++++++++++++++++++++++++---- 1 files changed, 29 insertions(+), 4 deletions(-) diff --git a/postler/postler-index.vala b/postler/postler-index.vala index ba963ba..e659ab3 100644 --- a/postler/postler-index.vala +++ b/postler/postler-index.vala @@ -13,6 +13,7 @@ namespace Postler { public class Index : GLib.Object, GLib.Initable { static Sqlite.Database? database = null; static Sqlite.Statement? statement_insert = null; + static Sqlite.Statement? statement_insert_sender = null; static Sqlite.Statement? statement_get = null; static Sqlite.Statement? statement_thread = null; static Sqlite.Statement? statement_list = null; @@ -103,6 +104,8 @@ namespace Postler { string[] indices = { "CREATE INDEX IF NOT EXISTS id_index ON messages (id);", "CREATE INDEX IF NOT EXISTS threads_index ON messages (threads);", + "CREATE TABLE IF NOT EXISTS senders (address TEXT, name TEXT)", + "CREATE INDEX IF NOT EXISTS senders_index ON senders (address);" }; foreach (string index_statement in indices) { if (database.exec (index_statement) != Sqlite.OK) @@ -110,6 +113,27 @@ namespace Postler { } } + public void insert_sender (string address) throws GLib.Error { + if (statement_insert_sender == null) { + if (database.prepare_v2 (""" + INSERT INTO senders (address, name) VALUES (?1, ?2) + """, + -1, out statement_insert_sender) != Sqlite.OK) + throw new GLib.FileError.FAILED (_("Failed to index message: %s"), database.errmsg ()); + } + string[] parts = Contact.parse (address); + /* Don't collect address <address> which is not useful */ + if (parts[0] == parts[1]) + return; + bool success = + statement_insert_sender.bind_text (1, parts[1], -1) == Sqlite.OK + && statement_insert_sender.bind_text (2, parts[0], -1) == Sqlite.OK + && statement_insert_sender.step () == Sqlite.DONE; + statement_insert_sender.reset (); + if (!success) + throw new GLib.FileError.FAILED (_("Failed to index message: %s"), database.errmsg ()); + } + public void insert_received_message (Message message) throws GLib.Error { if (statement_insert == null) { if (database.prepare_v2 (""" @@ -143,6 +167,7 @@ namespace Postler { statement_insert.reset (); if (!success) throw new GLib.FileError.FAILED (_("Failed to index message: %s"), database.errmsg ()); + insert_sender (message.sender); #if HAVE_ZEITGEIST var log = new Zeitgeist.Log (); var event = new Zeitgeist.Event.full (Zeitgeist.ZG_RECEIVE_EVENT, @@ -376,22 +401,22 @@ namespace Postler { if (statement_guess == null) { if (database.prepare_v2 (""" - SELECT sender FROM messages WHERE sender LIKE ?1 - GROUP BY sender ORDER BY COUNT (sender) DESC LIMIT 1 + SELECT name FROM senders WHERE address = ?1 + GROUP BY name ORDER BY COUNT (name) DESC LIMIT 1 """, -1, out statement_guess) != Sqlite.OK) throw new GLib.FileError.FAILED (_("Failed to guess name: %s"), database.errmsg ()); } int result = Sqlite.ERROR; bool success = - statement_guess.bind_text (1, "%<" + address + ">", -1) == Sqlite.OK + statement_guess.bind_text (1, address, -1) == Sqlite.OK && row_or_done (((result = statement_guess.step ()))); if (!success) { statement_guess.reset (); throw new GLib.FileError.FAILED (_("Failed to guess name: %s"), database.errmsg ()); } if (result == Sqlite.ROW) { - string display_name = Postler.Contact.name_from_string (statement_guess.column_text (0)); + string display_name = statement_guess.column_text (0); statement_guess.reset (); return new Postler.Contact (display_name, null); } _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org http://foo-projects.org/mailman/listinfo/xfce4-commits