changeset 22773:dbdb73e0a95a

lib-index: Code cleanup for reading caching decisions No functional changes.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Wed, 24 Jan 2018 18:01:23 +0200
parents e7177725a580
children 76387cd37d39
files src/lib-index/mail-cache-fields.c
diffstat 1 files changed, 17 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-cache-fields.c	Wed Jan 24 17:58:57 2018 +0200
+++ b/src/lib-index/mail-cache-fields.c	Wed Jan 24 18:01:23 2018 +0200
@@ -394,24 +394,35 @@
 			return -1;
 		}
 
+		/* ignore any forced-flags in the file */
+		enum mail_cache_decision_type file_dec =
+			decisions[i] & ~MAIL_CACHE_DECISION_FORCED;
+
 		if (hash_table_lookup_full(cache->field_name_hash, names,
 					   &orig_key, &orig_value)) {
 			/* already exists, see if decision can be updated */
 			fidx = POINTER_CAST_TO(orig_value, unsigned int);
-			if (!cache->fields[fidx].decision_dirty &&
-			    (cache->fields[fidx].field.decision &
-			     MAIL_CACHE_DECISION_FORCED) == 0) {
-				cache->fields[fidx].field.decision =
-					decisions[i] & ~MAIL_CACHE_DECISION_FORCED;
+			enum mail_cache_decision_type cur_dec =
+				cache->fields[fidx].field.decision;
+			if ((cur_dec & MAIL_CACHE_DECISION_FORCED) != 0) {
+				/* Forced decision. */
+			} else if (cache->fields[fidx].decision_dirty) {
+				/* Decisions have recently been updated
+				   internally. Don't change them. */
+			} else {
+				/* Use the decision from the cache file. */
+				cache->fields[fidx].field.decision = file_dec;
 			}
 			if (field_type_verify(cache, fidx,
 					      types[i], sizes[i]) < 0)
 				return -1;
 		} else {
+			/* field is currently unknown, so just use whatever
+			   exists in the file. */
 			field.name = names;
 			field.type = types[i];
 			field.field_size = sizes[i];
-			field.decision = decisions[i] & ~MAIL_CACHE_DECISION_FORCED;
+			field.decision = file_dec;
 			mail_cache_register_fields(cache, &field, 1);
 			fidx = field.idx;
 		}