[dovecot-cvs] dovecot/src/lib-storage/index index-mail-headers.c, 1.56, 1.57 index-mail.c, 1.89, 1.90 index-mail.h, 1.36, 1.37 index-storage.c, 1.81, 1.82 index-storage.h, 1.97, 1.98

cras at dovecot.org cras at dovecot.org
Thu Jan 19 00:16:49 EET 2006


Update of /var/lib/cvs/dovecot/src/lib-storage/index
In directory talvi:/tmp/cvs-serv7439/src/lib-storage/index

Modified Files:
	index-mail-headers.c index-mail.c index-mail.h index-storage.c 
	index-storage.h 
Log Message:
Added mail_cache_min_mail_count setting.



Index: index-mail-headers.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-mail-headers.c,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- index-mail-headers.c	14 Jan 2006 18:47:42 -0000	1.56
+++ index-mail-headers.c	18 Jan 2006 22:16:43 -0000	1.57
@@ -72,9 +72,7 @@
 						    mail->data.seq,
 						    match_idx) == 0) {
 				/* this header doesn't exist. remember that. */
-				mail_cache_add(mail->trans->cache_trans,
-					       mail->data.seq, match_idx,
-					       NULL, 0);
+				index_mail_cache_add(mail, match_idx, NULL, 0);
 			}
 			match_idx++;
 		}
@@ -123,8 +121,7 @@
 		}
 
 		data = buffer_get_data(buf, &data_size);
-		mail_cache_add(mail->trans->cache_trans, mail->data.seq,
-			       lines[i].field_idx, data, data_size);
+		index_mail_cache_add(mail, lines[i].field_idx, data, data_size);
 	}
 
 	for (; match_idx < match_count; match_idx++) {
@@ -132,8 +129,7 @@
 		    mail_cache_field_exists(mail->trans->cache_view,
 					    mail->data.seq, match_idx) == 0) {
 			/* this header doesn't exist. remember that. */
-			mail_cache_add(mail->trans->cache_trans,
-				       mail->data.seq, match_idx, NULL, 0);
+			index_mail_cache_add(mail, match_idx, NULL, 0);
 		}
 	}
 
@@ -152,10 +148,8 @@
 
 		/* check that it hadn't been added in some older session */
 		if (mail_cache_field_exists(mail->trans->cache_view,
-					    mail->data.seq, cache_field) == 0) {
-			mail_cache_add(mail->trans->cache_trans,
-				       mail->data.seq, cache_field, NULL, 0);
-		}
+					    mail->data.seq, cache_field) == 0)
+			index_mail_cache_add(mail, cache_field, NULL, 0);
 	}
 	t_pop();
 }
@@ -244,8 +238,8 @@
 	imap_envelope_write_part_data(mail->data.envelope_data, str);
 	mail->data.envelope = str_c(str);
 
-	mail_cache_add(mail->trans->cache_trans, mail->data.seq,
-		       MAIL_CACHE_IMAP_ENVELOPE, str_data(str), str_len(str));
+	index_mail_cache_add(mail, MAIL_CACHE_IMAP_ENVELOPE,
+			     str_data(str), str_len(str));
 }
 
 void index_mail_parse_header(struct message_part *part,
@@ -276,9 +270,9 @@
 	if (hdr == NULL) {
 		/* end of headers */
 		if (data->sent_date.time != (time_t)-1) {
-                        mail_cache_add(mail->trans->cache_trans, data->seq,
-				       MAIL_CACHE_SENT_DATE, &data->sent_date,
-				       sizeof(data->sent_date));
+			index_mail_cache_add(mail, MAIL_CACHE_SENT_DATE,
+					     &data->sent_date,
+					     sizeof(data->sent_date));
 		}
 		index_mail_parse_header_finish(mail);
                 data->save_bodystructure_header = FALSE;

Index: index-mail.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-mail.c,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -d -r1.89 -r1.90
--- index-mail.c	14 Jan 2006 18:47:42 -0000	1.89
+++ index-mail.c	18 Jan 2006 22:16:43 -0000	1.90
@@ -260,9 +260,9 @@
 			tz = 0;
 		}
 		data->sent_date.timezone = tz;
-		mail_cache_add(mail->trans->cache_trans, mail->data.seq,
-			       cache_fields[MAIL_CACHE_SENT_DATE].idx,
-			       &data->sent_date, sizeof(data->sent_date));
+		index_mail_cache_add(mail,
+				     cache_fields[MAIL_CACHE_SENT_DATE].idx,
+				     &data->sent_date, sizeof(data->sent_date));
 	}
 
 	if (timezone != NULL)
@@ -311,9 +311,9 @@
 	}
 
 	i_assert(data->virtual_size != (uoff_t)-1);
-	mail_cache_add(mail->trans->cache_trans, mail->data.seq,
-		       cache_fields[MAIL_CACHE_VIRTUAL_FULL_SIZE].idx,
-		       &data->virtual_size, sizeof(data->virtual_size));
+	index_mail_cache_add(mail,
+			     cache_fields[MAIL_CACHE_VIRTUAL_FULL_SIZE].idx,
+			     &data->virtual_size, sizeof(data->virtual_size));
 	return data->virtual_size;
 }
 
@@ -335,6 +335,21 @@
 	return (uoff_t)-1;
 }
 
+void index_mail_cache_add(struct index_mail *mail, unsigned int field,
+			  const void *data, size_t data_size)
+{
+	const struct mail_index_header *hdr;
+
+	/* First check if we've configured caching not to be used with
+	   low enough message count. */
+	hdr = mail_index_get_header(mail->ibox->view);
+	if (hdr->messages_count < mail->ibox->mail_cache_min_mail_count)
+		return;
+
+	mail_cache_add(mail->trans->cache_trans, mail->data.seq,
+		       field, data, data_size);
+}
+
 static void parse_bodystructure_part_header(struct message_part *part,
 					    struct message_header_line *hdr,
 					    void *context)
@@ -412,9 +427,8 @@
 
 	if (cache_flags != data->cache_flags) {
 		data->cache_flags = cache_flags;
-		mail_cache_add(mail->trans->cache_trans, mail->data.seq,
-			       cache_fields[MAIL_CACHE_FLAGS].idx,
-			       &cache_flags, sizeof(cache_flags));
+		index_mail_cache_add(mail, cache_fields[MAIL_CACHE_FLAGS].idx,
+				     &cache_flags, sizeof(cache_flags));
 	}
 
 	/* see if we want to cache the message part */
@@ -432,9 +446,9 @@
 		message_part_serialize(mail->data.parts, buffer);
 
 		buf_data = buffer_get_data(buffer, &buf_size);
-		mail_cache_add(mail->trans->cache_trans, mail->data.seq,
-			       cache_fields[MAIL_CACHE_MESSAGEPART].idx,
-			       buf_data, buf_size);
+                index_mail_cache_add(mail,
+				     cache_fields[MAIL_CACHE_MESSAGEPART].idx,
+				     buf_data, buf_size);
 		t_pop();
 		data->messageparts_saved_to_cache = TRUE;
 	}
@@ -548,7 +562,7 @@
 		if (!plain_bodystructure &&
 		    dec != (MAIL_CACHE_DECISION_NO |
 			    MAIL_CACHE_DECISION_FORCED)) {
-			mail_cache_add(mail->trans->cache_trans, data->seq,
+			index_mail_cache_add(mail,
 				cache_fields[MAIL_CACHE_IMAP_BODYSTRUCTURE].idx,
 				str_c(str), str_len(str)+1);
 			bodystructure_cached = TRUE;
@@ -568,7 +582,7 @@
 		if (!bodystructure_cached && !plain_bodystructure &&
 		    dec != (MAIL_CACHE_DECISION_NO |
 			    MAIL_CACHE_DECISION_FORCED)) {
-			mail_cache_add(mail->trans->cache_trans, data->seq,
+			index_mail_cache_add(mail,
 				       cache_fields[MAIL_CACHE_IMAP_BODY].idx,
 				       str_c(str), str_len(str)+1);
 		}

Index: index-mail.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-mail.h,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- index-mail.h	13 Jul 2005 08:25:24 -0000	1.36
+++ index-mail.h	18 Jan 2006 22:16:43 -0000	1.37
@@ -172,4 +172,7 @@
 uoff_t index_mail_get_cached_virtual_size(struct index_mail *mail);
 time_t index_mail_get_cached_received_date(struct index_mail *mail);
 
+void index_mail_cache_add(struct index_mail *mail, unsigned int field,
+			  const void *data, size_t data_size);
+
 #endif

Index: index-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-storage.c,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -d -r1.81 -r1.82
--- index-storage.c	14 Jan 2006 18:47:42 -0000	1.81
+++ index-storage.c	18 Jan 2006 22:16:43 -0000	1.82
@@ -225,7 +225,7 @@
 {
 	static bool initialized = FALSE;
 	struct mail_cache *cache = ibox->cache;
-	const char *cache_env, *never_env;
+	const char *cache_env, *never_env, *env;
 
 	if (!initialized) {
 		initialized = TRUE;
@@ -242,6 +242,10 @@
 		set_cache_decisions("mail_never_cache_fields", never_env,
 				    MAIL_CACHE_DECISION_NO |
 				    MAIL_CACHE_DECISION_FORCED);
+
+		env = getenv("MAIL_CACHE_MIN_MAIL_COUNT");
+		if (env != NULL)
+			ibox->mail_cache_min_mail_count = atoi(env);
 	}
 
 	ibox->cache_fields = i_malloc(sizeof(global_cache_fields));

Index: index-storage.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/index-storage.h,v
retrieving revision 1.97
retrieving revision 1.98
diff -u -d -r1.97 -r1.98
--- index-storage.h	13 Jan 2006 20:26:25 -0000	1.97
+++ index-storage.h	18 Jan 2006 22:16:43 -0000	1.98
@@ -64,8 +64,11 @@
 
 	const array_t *ARRAY_DEFINE_PTR(keyword_names, const char *);
 	struct mail_cache_field *cache_fields;
+	unsigned int mail_cache_min_mail_count;
+
 	buffer_t *recent_flags;
 	uint32_t recent_flags_start_seq, recent_flags_count;
+
 	uint32_t synced_recent_count;
 	time_t sync_last_check;
 



More information about the dovecot-cvs mailing list