track number of messages in IMAP stores

... rather than calculating it on the fly. for efficiency.
This commit is contained in:
Oswald Buddenhagen 2022-05-30 21:31:50 +02:00
parent 6fe7172901
commit df4e6383f5
3 changed files with 4 additions and 11 deletions

View File

@ -55,15 +55,6 @@ fmt_lone_flags( uchar flags )
return buf; return buf;
} }
uint
count_generic_messages( message_t *msgs )
{
uint count = 0;
for (; msgs; msgs = msgs->next)
count++;
return count;
}
void void
free_generic_messages( message_t *msgs ) free_generic_messages( message_t *msgs )
{ {

View File

@ -303,7 +303,6 @@ struct driver {
int (*get_fail_state)( store_conf_t *conf ); int (*get_fail_state)( store_conf_t *conf );
}; };
uint count_generic_messages( message_t * );
void free_generic_messages( message_t * ); void free_generic_messages( message_t * );
void parse_generic_store( store_conf_t *store, conffile_t *cfg, const char *type ); void parse_generic_store( store_conf_t *store, conffile_t *cfg, const char *type );

View File

@ -113,6 +113,7 @@ union imap_store {
int total_msgs, recent_msgs; int total_msgs, recent_msgs;
uint uidvalidity, uidnext; uint uidvalidity, uidnext;
imap_message_t **msgapp, *msgs; // FETCH results imap_message_t **msgapp, *msgs; // FETCH results
uint msgcnt;
uint caps; // CAPABILITY results uint caps; // CAPABILITY results
string_list_t *auth_mechs; string_list_t *auth_mechs;
parse_list_state_t parse_list_sts; parse_list_state_t parse_list_sts;
@ -1208,6 +1209,7 @@ parse_fetch_rsp( imap_store_t *ctx, list_t *list, char *s ATTR_UNUSED )
cur = nfzalloc( sizeof(*cur) ); cur = nfzalloc( sizeof(*cur) );
*ctx->msgapp = cur; *ctx->msgapp = cur;
ctx->msgapp = &cur->next; ctx->msgapp = &cur->next;
ctx->msgcnt++;
cur->uid = uid; cur->uid = uid;
cur->flags = mask; cur->flags = mask;
cur->status = status; cur->status = status;
@ -2631,6 +2633,7 @@ imap_select_box( store_t *gctx, const char *name )
free_generic_messages( &ctx->msgs->gen ); free_generic_messages( &ctx->msgs->gen );
ctx->msgs = NULL; ctx->msgs = NULL;
ctx->msgapp = &ctx->msgs; ctx->msgapp = &ctx->msgs;
ctx->msgcnt = 0;
ctx->name = name; ctx->name = name;
return DRV_OK; return DRV_OK;
@ -2935,7 +2938,7 @@ imap_sort_msgs_comp( const void *a_, const void *b_ )
static void static void
imap_sort_msgs( imap_store_t *ctx ) imap_sort_msgs( imap_store_t *ctx )
{ {
uint count = count_generic_messages( &ctx->msgs->gen ); uint count = ctx->msgcnt;
if (count <= 1) if (count <= 1)
return; return;