]> code.citadel.org Git - citadel.git/blobdiff - citadel/imap_misc.c
* Replication checks and EUID indexing are now only enabled for rooms whose
[citadel.git] / citadel / imap_misc.c
index 00c652f277dfd4a7d4c2acd9883956d384874ab2..7d616d1e484c137e2ddb3de452da578bc414cedf 100644 (file)
@@ -63,6 +63,7 @@ int imap_do_copy(char *destination_folder) {
        int i;
        char roomname[ROOMNAMELEN];
        struct ctdlroom qrbuf;
+       struct timeval tv1, tv2, tv3;
 
        if (IMAP->num_msgs < 1) {
                return(0);
@@ -71,6 +72,25 @@ int imap_do_copy(char *destination_folder) {
        i = imap_grabroom(roomname, destination_folder, 0);
        if (i != 0) return(i);
 
+       /*
+        * Optimization note ... ajc 2005oct09
+        * 
+        * As we can see below, we're going to end up making lots of
+        * repeated calls to CtdlCopyMsgToRoom() if the user selects
+        * multiple messages and then does a copy or move operation.
+        *
+        * The plan (documented in this comment so I don't forget what I was
+        * going to do) is to refactor CtdlCopyMsgToRoom() so that it accepts
+        * a list of message ID's instead of a single one.  Then we can alter
+        * the code which appears below, to copy all the message pointers in
+        * one shot.
+        * 
+        * But the REAL resource waster is further down, where we call
+        * the CtdlSetSeen() API for each message moved.  That's a HUGE
+        * performance drag.  Fix that too.
+        *
+        */
+       gettimeofday(&tv1, NULL);
        for (i = 0; i < IMAP->num_msgs; ++i) {
                if (IMAP->flags[i] & IMAP_SELECTED) {
                        CtdlCopyMsgToRoom(IMAP->msgids[i], roomname);
@@ -78,17 +98,18 @@ int imap_do_copy(char *destination_folder) {
        }
 
        /* Set the flags... */
+       gettimeofday(&tv2, NULL);
        i = getroom(&qrbuf, roomname);
        if (i != 0) return(i);
 
        for (i = 0; i < IMAP->num_msgs; ++i) {
                if (IMAP->flags[i] & IMAP_SELECTED) {
-                       CtdlSetSeen(IMAP->msgids[i],
+                       CtdlSetSeen(&IMAP->msgids[i], 1,
                                ((IMAP->flags[i] & IMAP_SEEN) ? 1 : 0),
                                ctdlsetseen_seen,
                                NULL, &qrbuf
                        );
-                       CtdlSetSeen(IMAP->msgids[i],
+                       CtdlSetSeen(&IMAP->msgids[i], 1,
                                ((IMAP->flags[i] & IMAP_ANSWERED) ? 1 : 0),
                                ctdlsetseen_answered,
                                NULL, &qrbuf
@@ -96,6 +117,15 @@ int imap_do_copy(char *destination_folder) {
                }
        }
 
+       gettimeofday(&tv3, NULL);
+       lprintf(CTDL_DEBUG, "Copying the pointers took %ld microseconds\n",
+               (tv2.tv_usec + (tv2.tv_sec * 1000))
+               - (tv1.tv_usec + (tv1.tv_sec * 1000))
+       );
+       lprintf(CTDL_DEBUG, "Setting the flags took %ld microseconds\n",
+               (tv3.tv_usec + (tv3.tv_sec * 1000))
+               - (tv2.tv_usec + (tv2.tv_sec * 1000))
+       );
        return(0);
 }
 
@@ -247,11 +277,11 @@ void imap_do_append_flags(long new_msgnum, char *new_message_flags) {
                extract_token(this_flag, flags, i, ' ', sizeof this_flag);
                if (this_flag[0] == '\\') strcpy(this_flag, &this_flag[1]);
                if (!strcasecmp(this_flag, "Seen")) {
-                       CtdlSetSeen(new_msgnum, 1, ctdlsetseen_seen,
+                       CtdlSetSeen(&new_msgnum, 1, 1, ctdlsetseen_seen,
                                NULL, NULL);
                }
                if (!strcasecmp(this_flag, "Answered")) {
-                       CtdlSetSeen(new_msgnum, 1, ctdlsetseen_answered,
+                       CtdlSetSeen(&new_msgnum, 1, 1, ctdlsetseen_answered,
                                NULL, NULL);
                }
        }