Permalink
Browse files

Suppress the dependencies on the now obsolete mail_status table.

  • Loading branch information...
manitou-mail committed Jul 5, 2017
1 parent ac4c90e commit 7804642c1b247c53822fd20642bfae380a650dfd
Showing with 23 additions and 19 deletions.
  1. +1 −1 src/msg_status_cache.cpp
  2. +6 −2 src/query_listview.cpp
  3. +16 −16 src/selectmail.cpp
View
@@ -104,7 +104,7 @@ msg_status_cache::db_new_mail_notif()
DBG_PRINTF(5, "We have NEW MAIL!");
db_cnx db;
try {
sql_stream s("SELECT ms.mail_id,ms.status,sender,sender_fullname,subject,recipients FROM mail m JOIN mail_status ms USING(mail_id) WHERE ms.mail_id>:p1", db);
sql_stream s("SELECT mail_id,status,sender,sender_fullname,subject,recipients FROM mail WHERE status&status_mask('archived')=0 AND mail_id>:p1", db);
s << m_max_mail_id;
mail_id_t mail_id;
int status;
View
@@ -467,8 +467,12 @@ query_listview::fetch_tag_map()
{
db_cnx db;
try {
int mask = mail_msg::statusTrashed + mail_msg::statusArchived + mail_msg::statusSent;
sql_stream s(QString("SELECT ms.mail_id,mt.tag,ms.status,m.priority FROM (mail m JOIN mail_status ms USING (mail_id)) LEFT OUTER JOIN mail_tags mt ON mt.mail_id=ms.mail_id WHERE ms.status&%1=0").arg(mask), db); // status is not (sent OR archived OR trashed)
// status is current (=NOT(sent OR archived OR trashed))
sql_stream s(QString("SELECT m.mail_id,mt.tag,m.status,m.priority "
"FROM mail m LEFT OUTER JOIN mail_tags mt ON mt.mail_id=m.mail_id "
"WHERE m.status&status_mask('archived')=0 AND m.status&%1=0")
.arg(mail_msg::statusSent|mail_msg::statusTrashed),
db);
mail_id_t mail_id;
unsigned int tag, status;
int pri;
View
@@ -393,17 +393,20 @@ msgs_filter::build_query(sql_query& q)
some particular values for the status */
if (m_status == -1 && !m_in_trash && m_status_set==0 && m_status_unset == mail_msg::statusArchived) {
// current and not tagged
q.add_clause(QString("m.mail_id in (SELECT ms.mail_id FROM mail_status ms"
" LEFT OUTER JOIN mail_tags mt ON mt.mail_id=ms.mail_id"
" WHERE mt.mail_id is null AND ms.status&%1=0)")
.arg(mail_msg::statusArchived|mail_msg::statusTrashed));
q.add_clause(QString("(m.status & status_mask('archived'))=0 AND"
" NOT EXISTS (SELECT 1 FROM mail_tags mt"
" WHERE mt.mail_id=m.mail_id)"));
done_with_status=true;
}
else if (m_status==0) {
// new and not tagged
q.add_clause(QString("m.mail_id in (SELECT ms.mail_id FROM mail_status ms"
" LEFT OUTER JOIN mail_tags mt ON mt.mail_id=ms.mail_id"
" WHERE mt.mail_id is null AND ms.status=0)"));
/* New and not tagged.
The (m.status & status_mask('archived')) clause is redundant
with (m.status=0) but it's used to let the planner use the partial
index on current mail. */
q.add_clause("(m.status & status_mask('archived'))=0 AND"
" m.status=0 AND"
" NOT EXISTS (SELECT 1 FROM mail_tags mt"
" WHERE mt.mail_id=m.mail_id)");
done_with_status=true;
}
else {
@@ -606,11 +609,9 @@ msgs_filter::build_query(sql_query& q)
s.sprintf("(status&%d=%d AND status&%d=0)", status_set, status_set, status_unset);
}
else {
if (status_unset == mail_msg::statusArchived ||
status_unset == mail_msg::statusArchived+mail_msg::statusTrashed) {
// unprocessed messages: optimize by joining with mail_status
q.add_table("mail_status ms");
s.sprintf("ms.mail_id=m.mail_id AND ms.status&%d=0", status_unset);
if (status_unset & mail_msg::statusArchived) {
// unprocessed messages: optimize by using the dedicated partial index
s.sprintf("status&status_mask('archived')=0 AND status&%d=0", status_unset);
}
else {
s.sprintf("status&%d=0", status_unset);
@@ -620,9 +621,8 @@ msgs_filter::build_query(sql_query& q)
}
if (m_status!=-1 && !done_with_status) {
if (m_status==0) {
// new messages: optimize by joining with mail_status
q.add_table("mail_status ms");
q.add_clause("ms.mail_id=m.mail_id AND ms.status=0");
// new messages: optimize by using the dedicated partial index
q.add_clause("status&status_mask('archived')=0 AND status=0");
}
else {
QString s;

0 comments on commit 7804642

Please sign in to comment.