annotate src/lib-index/mail-cache-decisions.c @ 22713:cb108f786fb4

Updated copyright notices to include the year 2018.
author Stephan Bosch <stephan.bosch@dovecot.fi>
date Mon, 01 Jan 2018 22:42:08 +0100
parents d64bd3f11bdf
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22713
cb108f786fb4 Updated copyright notices to include the year 2018.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21428
diff changeset
1 /* Copyright (c) 2004-2018 Dovecot authors, see the included COPYING file */
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
2259
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
3 /*
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
4 Users can be divided to three groups:
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
5
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
6 1. Most users will use only a single IMAP client which caches everything
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
7 locally. For these users it's quite pointless to do any kind of caching
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
8 as it only wastes disk space. That might also mean more disk I/O.
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
9
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
10 2. Some users use multiple IMAP clients which cache everything locally.
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
11 These could benefit from caching until all clients have fetched the
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
12 data. After that it's useless.
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
13
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
14 3. Some clients don't do permanent local caching at all. For example
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
15 Pine and webmails. These clients would benefit from caching everything.
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
16 Some locally caching clients might also access some data from server
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
17 again, such as when searching messages. They could benefit from caching
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
18 only these fields.
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
19
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
20 After thinking about these a while, I figured out that people who care
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
21 about performance most will be using Dovecot optimized LDA anyway
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
22 which updates the indexes/cache immediately. In that case even the first
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
23 user group would benefit from caching the same way as second group. LDA
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
24 reads the mail anyway, so it might as well extract some information
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
25 about it and store them into cache.
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
26
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
27 So, group 1. and 2. could be optimally implemented by keeping things
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
28 cached only for a while. I thought a week would be good. When cache file
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
29 is compressed, everything older than week will be dropped.
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
30
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
31 But how to figure out if user is in group 3? One quite easy rule would
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
32 be to see if client is accessing messages older than a week. But with
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
33 only that rule we might have already dropped useful cached data. It's
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
34 not very nice if we have to read and cache it twice.
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
35
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
36 Most locally caching clients always fetch new messages (all but body)
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
37 when they see them. They fetch them in ascending order. Noncaching
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
38 clients might fetch messages in pretty much any order, as they usually
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
39 don't fetch everything they can, only what's visible in screen. Some
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
40 will use server side sorting/threading which also makes messages to be
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
41 fetched in random order. Second rule would then be that if a session
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
42 doesn't fetch messages in ascending order, the fetched field type will
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
43 be permanently cached.
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
44
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
45 So, we have three caching decisions:
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
46
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
47 1. Don't cache: Clients have never wanted the field
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
48 2. Cache temporarily: Clients want this only once
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
49 3. Cache permanently: Clients want this more than once
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
50
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
51 Different mailboxes have different decisions. Different fields have
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
52 different decisions.
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
53
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
54 There are some problems, such as if a client accesses message older than
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
55 a week, we can't know if user just started using a new client which is
3551
65dc45982df9 Removed fcntl() text from some locking error messages, because if
Timo Sirainen <tss@iki.fi>
parents: 2892
diff changeset
56 just filling its local cache for the first time. Or it might be a
2259
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
57 client user hasn't just used for over a week. In these cases we
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
58 shouldn't have marked the field to be permanently cached. User might
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
59 also switch clients from non-caching to caching.
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
60
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
61 So we should re-evaluate our caching decisions from time to time. This
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
62 is done by checking the above rules constantly and marking when was the
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
63 last time the decision was right. If decision hasn't matched for two
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
64 months, it's changed. I picked two months because people go to at least
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
65 one month vacations where they might still be reading mails, but with
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
66 different clients.
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
67 */
07c8813877cc Cache decision explanation comment.
Timo Sirainen <tss@iki.fi>
parents: 2247
diff changeset
68
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 #include "lib.h"
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
70 #include "ioloop.h"
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 #include "mail-cache-private.h"
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72
5734
5f0832288007 Cache code cleanups
Timo Sirainen <tss@iki.fi>
parents: 3551
diff changeset
73 void mail_cache_decision_state_update(struct mail_cache_view *view,
5f0832288007 Cache code cleanups
Timo Sirainen <tss@iki.fi>
parents: 3551
diff changeset
74 uint32_t seq, unsigned int field)
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 {
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
76 struct mail_cache *cache = view->cache;
13840
95524ab3469f lib-index: If cache field's decision is forced no, don't update the field's last_used.
Timo Sirainen <tss@iki.fi>
parents: 13328
diff changeset
77 enum mail_cache_decision_type dec;
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78 const struct mail_index_header *hdr;
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
79 uint32_t uid;
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
80
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
81 i_assert(field < cache->fields_count);
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
82
13328
4a19aea565f7 lib-index: Added mail_cache_view_update_cache_decisions()
Timo Sirainen <tss@iki.fi>
parents: 12782
diff changeset
83 if (view->no_decision_updates)
4a19aea565f7 lib-index: Added mail_cache_view_update_cache_decisions()
Timo Sirainen <tss@iki.fi>
parents: 12782
diff changeset
84 return;
4a19aea565f7 lib-index: Added mail_cache_view_update_cache_decisions()
Timo Sirainen <tss@iki.fi>
parents: 12782
diff changeset
85
13840
95524ab3469f lib-index: If cache field's decision is forced no, don't update the field's last_used.
Timo Sirainen <tss@iki.fi>
parents: 13328
diff changeset
86 dec = cache->fields[field].field.decision;
95524ab3469f lib-index: If cache field's decision is forced no, don't update the field's last_used.
Timo Sirainen <tss@iki.fi>
parents: 13328
diff changeset
87 if (dec == (MAIL_CACHE_DECISION_NO | MAIL_CACHE_DECISION_FORCED)) {
95524ab3469f lib-index: If cache field's decision is forced no, don't update the field's last_used.
Timo Sirainen <tss@iki.fi>
parents: 13328
diff changeset
88 /* don't update last_used */
95524ab3469f lib-index: If cache field's decision is forced no, don't update the field's last_used.
Timo Sirainen <tss@iki.fi>
parents: 13328
diff changeset
89 return;
95524ab3469f lib-index: If cache field's decision is forced no, don't update the field's last_used.
Timo Sirainen <tss@iki.fi>
parents: 13328
diff changeset
90 }
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91
13842
ce29836e369e lib-index: Allow updating cache's last_used field with mail_cache_register_fields()
Timo Sirainen <tss@iki.fi>
parents: 13840
diff changeset
92 if (ioloop_time - cache->fields[field].field.last_used > 3600*24) {
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
93 /* update last_used about once a day */
13842
ce29836e369e lib-index: Allow updating cache's last_used field with mail_cache_register_fields()
Timo Sirainen <tss@iki.fi>
parents: 13840
diff changeset
94 cache->fields[field].field.last_used = (uint32_t)ioloop_time;
7076
3cb00348ed06 Update caching decision for fields even if it doesn't currently exist in the
Timo Sirainen <tss@iki.fi>
parents: 7069
diff changeset
95 if (cache->field_file_map[field] != (uint32_t)-1)
3cb00348ed06 Update caching decision for fields even if it doesn't currently exist in the
Timo Sirainen <tss@iki.fi>
parents: 7069
diff changeset
96 cache->field_header_write_pending = TRUE;
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
97 }
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
98
13840
95524ab3469f lib-index: If cache field's decision is forced no, don't update the field's last_used.
Timo Sirainen <tss@iki.fi>
parents: 13328
diff changeset
99 if (dec != MAIL_CACHE_DECISION_TEMP) {
7069
46d531d521b9 Update last_used also for decision=yes cache fields, otherwise they get
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
100 /* a) forced decision
46d531d521b9 Update last_used also for decision=yes cache fields, otherwise they get
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
101 b) not cached, mail_cache_decision_add() will handle this
46d531d521b9 Update last_used also for decision=yes cache fields, otherwise they get
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
102 c) permanently cached already, okay. */
46d531d521b9 Update last_used also for decision=yes cache fields, otherwise they get
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
103 return;
46d531d521b9 Update last_used also for decision=yes cache fields, otherwise they get
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
104 }
46d531d521b9 Update last_used also for decision=yes cache fields, otherwise they get
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
105
13840
95524ab3469f lib-index: If cache field's decision is forced no, don't update the field's last_used.
Timo Sirainen <tss@iki.fi>
parents: 13328
diff changeset
106 mail_index_lookup_uid(view->view, seq, &uid);
95524ab3469f lib-index: If cache field's decision is forced no, don't update the field's last_used.
Timo Sirainen <tss@iki.fi>
parents: 13328
diff changeset
107 hdr = mail_index_get_header(view->view);
95524ab3469f lib-index: If cache field's decision is forced no, don't update the field's last_used.
Timo Sirainen <tss@iki.fi>
parents: 13328
diff changeset
108
7069
46d531d521b9 Update last_used also for decision=yes cache fields, otherwise they get
Timo Sirainen <tss@iki.fi>
parents: 6429
diff changeset
109 /* see if we want to change decision from TEMP to YES */
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
110 if (uid < cache->fields[field].uid_highwater ||
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
111 uid < hdr->day_first_uid[7]) {
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
112 /* a) nonordered access within this session. if client doesn't
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
113 request messages in growing order, we assume it doesn't
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
114 have a permanent local cache.
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
115 b) accessing message older than one week. assume it's a
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
116 client with no local cache. if it was just a new client
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
117 generating the local cache for the first time, we'll
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118 drop back to TEMP within few months. */
2339
406692edc12d Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
119 cache->fields[field].field.decision = MAIL_CACHE_DECISION_YES;
2865
604e9488a61b mark decision changes dirty so when we're trying to write them to disk, we
Timo Sirainen <tss@iki.fi>
parents: 2342
diff changeset
120 cache->fields[field].decision_dirty = TRUE;
7076
3cb00348ed06 Update caching decision for fields even if it doesn't currently exist in the
Timo Sirainen <tss@iki.fi>
parents: 7069
diff changeset
121
3cb00348ed06 Update caching decision for fields even if it doesn't currently exist in the
Timo Sirainen <tss@iki.fi>
parents: 7069
diff changeset
122 if (cache->field_file_map[field] != (uint32_t)-1)
3cb00348ed06 Update caching decision for fields even if it doesn't currently exist in the
Timo Sirainen <tss@iki.fi>
parents: 7069
diff changeset
123 cache->field_header_write_pending = TRUE;
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
124 } else {
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
125 cache->fields[field].uid_highwater = uid;
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
126 }
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
127 }
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
128
2298
5beb0c20b6e8 Cache file fixes, API changes, etc. It's still in somewhat ugly state, but
Timo Sirainen <tss@iki.fi>
parents: 2275
diff changeset
129 void mail_cache_decision_add(struct mail_cache_view *view, uint32_t seq,
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
130 unsigned int field)
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
131 {
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
132 struct mail_cache *cache = view->cache;
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
133 uint32_t uid;
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
134
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
135 i_assert(field < cache->fields_count);
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
136
13328
4a19aea565f7 lib-index: Added mail_cache_view_update_cache_decisions()
Timo Sirainen <tss@iki.fi>
parents: 12782
diff changeset
137 if (MAIL_CACHE_IS_UNUSABLE(cache) || view->no_decision_updates)
2275
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2259
diff changeset
138 return;
c68a3c9f6d73 Cache file compression works now and compressed cache file is reopened.
Timo Sirainen <tss@iki.fi>
parents: 2259
diff changeset
139
2339
406692edc12d Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
140 if (cache->fields[field].field.decision != MAIL_CACHE_DECISION_NO) {
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
141 /* a) forced decision
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
142 b) we're already caching it, so it just wasn't in cache */
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
143 return;
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
144 }
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
145
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
146 /* field used the first time */
2339
406692edc12d Cache fixes. Decisions are saved again.
Timo Sirainen <tss@iki.fi>
parents: 2327
diff changeset
147 cache->fields[field].field.decision = MAIL_CACHE_DECISION_TEMP;
2865
604e9488a61b mark decision changes dirty so when we're trying to write them to disk, we
Timo Sirainen <tss@iki.fi>
parents: 2342
diff changeset
148 cache->fields[field].decision_dirty = TRUE;
2327
7d02e2a7672d Header caching redesigned. New design allows caching decisions per field, so
Timo Sirainen <tss@iki.fi>
parents: 2298
diff changeset
149 cache->field_header_write_pending = TRUE;
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
150
6275
913b188f4dd4 Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents: 5734
diff changeset
151 mail_index_lookup_uid(view->view, seq, &uid);
913b188f4dd4 Removed explicit locking from views and maps. They were already locked all
Timo Sirainen <tss@iki.fi>
parents: 5734
diff changeset
152 cache->fields[field].uid_highwater = uid;
2247
2d51bb58a070 Added some smartness for deciding what to cache. Cache compression code compiles, but untested.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
153 }
21428
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
154
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
155 void mail_cache_decisions_copy(struct mail_index_transaction *itrans,
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
156 struct mail_cache *src,
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
157 struct mail_cache *dst)
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
158 {
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
159 struct mail_cache_compress_lock *lock = NULL;
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
160
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
161 if (mail_cache_open_and_verify(src) < 0 ||
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
162 MAIL_CACHE_IS_UNUSABLE(src))
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
163 return;
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
164
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
165 unsigned int count = 0;
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
166 struct mail_cache_field *fields =
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
167 mail_cache_register_get_list(src, pool_datastack_create(), &count);
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
168 i_assert(fields != NULL || count == 0);
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
169 if (count > 0)
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
170 mail_cache_register_fields(dst, fields, count);
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
171
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
172 dst->field_header_write_pending = TRUE;
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
173 (void)mail_cache_compress(dst, itrans, &lock);
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
174 if (lock != NULL)
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
175 mail_cache_compress_unlock(&lock);
d64bd3f11bdf lib-index: Add mail_cache_decisions_copy
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 21390
diff changeset
176 }