dbmail-3.2.4 Backport: group_concat issue

This commit is contained in:
Sandino Araico Sanchez 2021-11-08 15:53:45 -06:00
parent 5e4cceb6d9
commit f058909c36
2 changed files with 162 additions and 4 deletions

View file

@ -5,7 +5,7 @@ AUX README.gentoo 1652 BLAKE2B beb9d27ac8de471d4ac8a3c4f626e7005d471477943b424b2
AUX dbmail-2.0.11-lcrypt.patch 642 BLAKE2B 211081aff5d1597054be134f091fce21d36e083d254f53803cb87de66b77cbd35160d548f3d7d6b43c8dfdb93cd4a533dda009f7ce9d5c7f69f5a8fe1fbe9835 SHA512 aa3c25ab2206f104e4de6b20929d55c0e3ceeebd41a670dea553797486696b145feee47f720f4043a1b1fa6b37c73c1684eeb467eace5142e1090a08b63044ff
AUX dbmail-2.0.4-01_quota.patch 5108 BLAKE2B 4b6ccfef889abcc50679d23e1f250fa46097f0f344cc080f218e06ab36e4ba44e01c33ced11fe4b508fcff40c7656fe80b5d11b94178e8e1028285d38c73a002 SHA512 3cbc50be3d2766185a37e627e7e2b7f737a083821755b099b6fade2aa3163ca291b368346a961c32dd40892dd3de64c6fa901980fa8c5d54e573a3b9d7e1d050
AUX dbmail-2.0.4-fPIC.patch 2871 BLAKE2B 3c87fba8ccd33efc2b7d875f15c6e146f9493a7930b0e5103a0fa5da6c669a6ebaa86857e6bd8ce1ad9a52e0a4d1177c6133830c4f7b6b09b3a98f4f22ea610f SHA512 dffcc1f79bb1dd4e38aa1842c1aac38fde44ef56c0152013eecabb293154d2d0045596f13321f4c07aaee63e5cf02663305042db5842d612bef461c98fbb67ef
AUX dbmail-3.2.4-group_concat.patch 678 BLAKE2B 3c4a6feba376308a05b24b47baf198e5f6a85d3ec697dc545ca31a8a03de25162dcb7ea50e268b96a31e13e37f593ea9288e2d407529e2e4bbf0eaa90cfeb12c SHA512 f0d5e77dfd5953478ebddb518c16813362e2d6466a1702a580bd89a6a486022433d184446b4de1038f4b19cadd7d76f5fbc172a8c4c8d080ff21ba47f164e283
AUX dbmail-3.2.4-group_concat.patch 5504 BLAKE2B b9ffc4949913c53bf2cf22b99da551755a80284016ba0fabb4dc7cdc4f83f3fcc978c7d7608e395b087b9f9d6c8f0a92753f73b41988c438a54c9a078a2b7885 SHA512 050891f01eb9a4f419b226897df5a43bdfac7e91fcc2794d75f79424b0b1fcd2f907c39a72e0d34dfd5b5d34bf90ce85dae03f3b2710e4743f37537215350420
AUX dbmail-3.2.5-crypt.patch 874 BLAKE2B bd550f1f0c0fe06b87c380a41a3a4a870978511871b4fd2d8367cf683d5fc0e7f66df2ae29abd94c7efca449294de69ea500e0e9f67c7d45c9216e1c64385d46 SHA512 abf0b859cadbb5eeceacd3c23edf7d94c90c70ebf6308de42ccb69e9bfbf59b0ac697f80476f2422647e5433d6f5ad4fc67262b302011b53c841e57fdb9ec39a
AUX dbmail-3.2.5-debug.patch 1475 BLAKE2B c0c466c6dd1cb0f6479e81a280ad4746db7b36d175f6bca50649f4b7833ce527c269743267c0cecc92831d3d41297cfa468581741bdbd42f979b008764640170 SHA512 4be630f5c2cd9aaf2eb3cf37fa61c64c5bfe03f916d9de7936e212dcd16b8129fdf0d746fef0ca86b93552251bd21beaafca43e4564a2728861d59a1cc3b2207
AUX dbmail-imapd.initd 726 BLAKE2B 98627190c184c837480c7fcbe5ee2afa7118de0a299a89c9d7b9a38fdb0b389df734504f79bb361d52324000e1dd2e6d20c64af47e1d81e2808e2cb3c8acc028 SHA512 3a9b175dfa189d74a241f770f701e07d0555e94c45ab162256d60972e4368bea7f9f040f2fa0e1d35969253d8c17fedf1d68f11e975084146d41219067f46486

View file

@ -1,7 +1,96 @@
Binary files dbmail-3.2.4.orig/src/.dm_mailboxstate.c.swp and dbmail-3.2.4/src/.dm_mailboxstate.c.swp differ
diff -uriN dbmail-3.2.4.orig/src/dm_mailboxstate.c dbmail-3.2.4/src/dm_mailboxstate.c
--- dbmail-3.2.4.orig/src/dm_mailboxstate.c 2020-06-08 02:19:38.000000000 -0500
+++ dbmail-3.2.4/src/dm_mailboxstate.c 2021-11-08 15:40:45.000000000 -0600
@@ -233,10 +233,10 @@
+++ dbmail-3.2.4/src/dm_mailboxstate.c 2021-11-08 15:52:10.000000000 -0600
@@ -91,6 +91,7 @@
unsigned nrows = 0, i = 0, j;
struct timeval before, after;
const char *query_result;
+ uint64_t tempId;
MessageInfo *result;
GTree *msginfo;
uint64_t *uid, id = 0;
@@ -99,13 +100,16 @@
Field_T frag;
INIT_QUERY;
char filterCondition[64]; memset(filterCondition,0,64);
+ /* the initialization should be done elsewhere, see ols MailboxState_new and MailboxState_update */
+ msginfo=MailboxState_getMsginfo(M);
+
if (coldLoad){
- msginfo = g_tree_new_full((GCompareDataFunc)ucmpdata, NULL,(GDestroyNotify)g_free,(GDestroyNotify)MessageInfo_free);
+ //msginfo = g_tree_new_full((GCompareDataFunc)ucmpdata, NULL,(GDestroyNotify)g_free,(GDestroyNotify)MessageInfo_free);
TRACE(TRACE_DEBUG, "SEQ New");
snprintf(filterCondition,64-1,"/*SEQ New*/ AND m.status < %d ", MESSAGE_STATUS_DELETE);
}else{
uint64_t seq=MailboxState_getSeq(M);
- msginfo=MailboxState_getMsginfo(M);
+ //msginfo=MailboxState_getMsginfo(M);
TRACE(TRACE_DEBUG, "SEQ RENew");
//MailboxState_uid_msn_new(M);
@@ -141,22 +145,26 @@
i++;
id = db_result_get_u64(r, IMAP_NFLAGS + 3);
-
- uid = g_new0(uint64_t,1); *uid = id;
+ /* reset */
+ shouldAdd=0;
if (coldLoad){
/* new element*/
result = g_new0(MessageInfo,1);
+ uid = g_new0(uint64_t,1);
+ *uid = id;
shouldAdd=1;
result->expunge=0;
result->expunged=0;
//TRACE(TRACE_DEBUG, "SEQ CREATED %ld",id);
}else{
/* soft renew, so search */
- result = g_tree_lookup(msginfo, &id);
- if (result==NULL){
+ result = g_tree_lookup(msginfo, &id);
+ if (result == NULL){
/* not found so create*/
result = g_new0(MessageInfo,1);
+ uid = g_new0(uint64_t,1);
+ *uid = id;
shouldAdd=1;
result->expunge=0;
result->expunged=0;
@@ -203,8 +211,10 @@
}else{
if (shouldAdd==1){
/* message is in state of state=2 or already deleted but not in our state */
+ g_tree_remove(msginfo,uid);
g_free(result);
- continue;
+ g_free(uid);
+ continue;
}
}
@@ -213,11 +223,9 @@
if (shouldAdd==1){
//TRACE(TRACE_DEBUG, "SEQ ADDED %ld",id);
/* it's new */
- g_tree_insert(msginfo, uid, result);
+ g_tree_insert(msginfo, uid, result);
}else{
- /* do not forget to remove unused references */
- //g_free(uid);
- //g_free(result);
+ /* no need, result was updated */
}
}
@@ -229,14 +237,14 @@
}
db_con_clear(c);
- //Optimize Keywords search, Cosmin Cioranu
memset(query, 0, sizeof(query));
snprintf(query, DEF_QUERYSIZE-1,
@ -10,7 +99,76 @@ diff -uriN dbmail-3.2.4.orig/src/dm_mailboxstate.c dbmail-3.2.4/src/dm_mailboxst
"LEFT JOIN %smessages m ON k.message_idnr=m.message_idnr "
"WHERE m.mailbox_idnr = ? %s "
- "group by m.message_idnr",
+ "group by k.message_idnr, k.keyword",
+ "order by m.message_idnr "
+ ,
DBPFX, DBPFX,
filterCondition);
@@ -245,40 +253,22 @@
db_stmt_set_u64(stmt, 1, M->id);
r = db_stmt_query(stmt);
gettimeofday(&before, NULL);
+ tempId=0;
+
while (db_result_next(r)) {
nrows++;
id = db_result_get_u64(r,0);
- /* process keywords, keywords are grouped by in order to avoid search over tree */
- const char * keywords = db_result_get(r,1);
- TRACE(TRACE_INFO, "Keyword line [%d %s]", nrows, keywords);
- if (strlen(keywords)>0){
- if ((result = g_tree_lookup(msginfo, &id)) != NULL){
- /* keywords, splitting */
- GList *klist = NULL;
- GString *t;
- t = g_string_new(keywords);
- klist = g_string_split(t, ",");
- g_string_free(t,TRUE);
- klist = g_list_first(klist);
- while(klist) {
- char *keyword = (char *)klist->data;
- TRACE(TRACE_INFO, "\tKeyword %s", keyword);
- if (strlen(keyword) < 1) continue;
- result->keywords = g_list_append(result->keywords, g_strdup(keyword));
- if (! g_list_next(klist)) break;
- klist = g_list_next(klist);
- }
- g_list_destroy(klist);
- /*
- char delim[] = ",";
- char *keyword = strtok(keywords, delim);
- while(keyword != NULL){
- //TRACE(TRACE_INFO, "Keyword [%s]", keyword);
- result->keywords = g_list_append(result->keywords, g_strdup(keyword));
- keyword = strtok(NULL, delim);
- }
- */
+ const char * keyword = db_result_get(r,1);
+ if (strlen(keyword)>0){
+ TRACE(TRACE_INFO, "Keyword line [%d %s]", nrows, keyword);
+ /* id is presented via query in ordered fashion so, we use tempId as a cached last tree lookup */
+ if ( tempId!=id || tempId==0 ){
+ result = g_tree_lookup(msginfo, &id);
+ tempId=id;
+ }
+ if ( result != NULL ){
+ result->keywords = g_list_append(result->keywords, g_strdup(keyword));
}
}
}
@@ -286,12 +276,8 @@
gettimeofday(&after, NULL);
log_query_time("Parsing Keywords ",before,after);
- if (coldLoad){
- MailboxState_setMsginfo(M, msginfo);
- }else{
- MailboxState_remap(M);
- }
-
+ /* on both cases can use the same function due to some checks at MailboxState_setMsgInfo*/
+ MailboxState_setMsginfo(M, msginfo);
return M;
}