[geary/wip/768431-forwarded-in-conversation] WIP implementation to include forwarded messages in conversation.



commit 852e8144d633c7fd0c29d35b05ef5d7d087dae71
Author: Michael James Gratton <mike vee net>
Date:   Sun Jul 31 13:17:21 2016 +1000

    WIP implementation to include forwarded messages in conversation.
    
    There's two parts to this: First, add a References header to the
    forwarded messages for the conversation they are a part of. Second, check
    for matching references when querying for related messages, in addition
    to in-reply-to.
    
    This would all be well and good, except that since the References header
    is a list of message ids, but it is stored in the DB as a single string,
    the query has to be a substring match, which is horrifically slow.
    
    This WIP adds an index, but it doesn't help, since SQLite only uses the
    index if using GLOB or case-insensitiive ILIKE, and only if there is no
    wild card at the start of the string, which we need to do. So the correct
    solution would be to split the References header into its own table.
    
    Bug 768431
    
    * sql/CMakeLists.txt: Add new SQL migration script.
    
    * sql/version-025.sql: Create index for MessageTable.reference_ids.
    
    * src/client/composer/composer-widget.vala
      (ComposerWidget::ComposerWidget): Add references to outoging forwarded
      messages.
    
    * src/engine/imap-db/imap-db-account.vala
      (Geary.ImapDB.Account::search_message_id_async): Include references in
      when searching for messages.

 sql/CMakeLists.txt                       |    1 +
 sql/version-025.sql                      |    6 ++++++
 src/client/composer/composer-widget.vala |    1 +
 src/engine/imap-db/imap-db-account.vala  |    9 ++++++---
 4 files changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt
index 11de86c..c89b8c9 100644
--- a/sql/CMakeLists.txt
+++ b/sql/CMakeLists.txt
@@ -24,3 +24,4 @@ install(FILES version-021.sql DESTINATION ${SQL_DEST})
 install(FILES version-022.sql DESTINATION ${SQL_DEST})
 install(FILES version-023.sql DESTINATION ${SQL_DEST})
 install(FILES version-024.sql DESTINATION ${SQL_DEST})
+install(FILES version-025.sql DESTINATION ${SQL_DEST})
diff --git a/sql/version-025.sql b/sql/version-025.sql
new file mode 100644
index 0000000..7b03998
--- /dev/null
+++ b/sql/version-025.sql
@@ -0,0 +1,6 @@
+--
+-- Add an index for MessageTable.reference_ids for finding related
+-- forwarded messages.
+--
+
+CREATE INDEX MessageTableReferenceIdsIndex ON MessageTable(reference_ids);
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 0387195..b0ce97c 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -511,6 +511,7 @@ public class ComposerWidget : Gtk.EventBox {
                 
                 case ComposeType.FORWARD:
                     subject = forward_subject;
+                    references = Geary.RFC822.Utils.reply_references(referred);
                     body_html = "\n\n" + Geary.RFC822.Utils.quote_email_for_forward(referred, quote,
                         Geary.RFC822.TextFormat.HTML);
                     add_attachments(referred.attachments);
diff --git a/src/engine/imap-db/imap-db-account.vala b/src/engine/imap-db/imap-db-account.vala
index 3078648..41ee215 100644
--- a/src/engine/imap-db/imap-db-account.vala
+++ b/src/engine/imap-db/imap-db-account.vala
@@ -830,12 +830,15 @@ private class Geary.ImapDB.Account : BaseObject {
         
         if (flag_blacklist != null)
             requested_fields = requested_fields | Geary.Email.Field.FLAGS;
-        
+
         yield db.exec_transaction_async(Db.TransactionType.RO, (cx) => {
-            Db.Statement stmt = cx.prepare("SELECT id FROM MessageTable WHERE message_id = ? OR in_reply_to 
= ?");
+            Db.Statement stmt = cx.prepare(
+                "SELECT id FROM MessageTable WHERE message_id = ? OR in_reply_to = ? or instr(reference_ids, 
?) > 0"
+            );
             stmt.bind_string(0, message_id.value);
             stmt.bind_string(1, message_id.value);
-            
+            stmt.bind_string(2, message_id.value);
+
             Db.Result result = stmt.exec(cancellable);
             while (!result.finished) {
                 int64 id = result.int64_at(0);


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