From 2027068ca24de1d870d72da7fbde42e00b54537a Mon Sep 17 00:00:00 2001 From: "naving%netscape.com" Date: Tue, 1 May 2001 22:01:43 +0000 Subject: [PATCH] 78280 The reason it was broken was because m_hdrs was not being built after sorting. No need for m_hdrs because we already have m_keys and can fetch the hdrs. m_keys and m_folders are rebuilt on a sort operation. 75761 The problem is with first message for local folders because they have m_messageKey as 0 and we were caching msg headers. This was causing problems for search window because results are from multiple folders. fix suggested by david. r=gayatrib sr=bienvenu --- mailnews/base/src/nsMsgDBView.cpp | 42 +++++++++++-------------- mailnews/base/src/nsMsgSearchDBView.cpp | 12 +++---- mailnews/base/src/nsMsgSearchDBView.h | 1 - 3 files changed, 23 insertions(+), 32 deletions(-) diff --git a/mailnews/base/src/nsMsgDBView.cpp b/mailnews/base/src/nsMsgDBView.cpp index e0df7df2ca0..8d000637227 100644 --- a/mailnews/base/src/nsMsgDBView.cpp +++ b/mailnews/base/src/nsMsgDBView.cpp @@ -669,17 +669,7 @@ NS_IMETHODIMP nsMsgDBView::GetCellProperties(PRInt32 aRow, const PRUnichar *colI nsCOMPtr msgHdr; nsresult rv = NS_OK; - if (key == m_cachedMsgKey) - msgHdr = m_cachedHdr; - else - { - rv = GetMsgHdrForViewIndex(aRow, getter_AddRefs(msgHdr)); - if (NS_SUCCEEDED(rv)) - { - m_cachedHdr = msgHdr; - m_cachedMsgKey = key; - } - } + rv = GetMsgHdrForViewIndex(aRow, getter_AddRefs(msgHdr)); if (NS_FAILED(rv) || !msgHdr) { ClearHdrCache(); @@ -858,11 +848,25 @@ NS_IMETHODIMP nsMsgDBView::GetLevel(PRInt32 index, PRInt32 *_retval) // search view will override this since headers can span db's nsresult nsMsgDBView::GetMsgHdrForViewIndex(nsMsgViewIndex index, nsIMsgDBHdr **msgHdr) { + nsresult rv = NS_OK; nsMsgKey key = m_keys.GetAt(index); if (key == nsMsgKey_None || !m_db) return NS_MSG_INVALID_DBVIEW_INDEX; + + if (key == m_cachedMsgKey) + *msgHdr = m_cachedHdr; + else + { + rv = m_db->GetMsgHdrForKey(key, msgHdr); + if (NS_SUCCEEDED(rv)) + { + m_cachedHdr = *msgHdr; + m_cachedMsgKey = key; + } + } + NS_IF_ADDREF(*msgHdr); - return m_db->GetMsgHdrForKey(key, msgHdr); + return rv; } nsresult nsMsgDBView::GetFolderForViewIndex(nsMsgViewIndex index, nsIMsgFolder **aFolder) @@ -888,18 +892,8 @@ NS_IMETHODIMP nsMsgDBView::GetCellText(PRInt32 aRow, const PRUnichar * aColID, P nsMsgKey key = m_keys.GetAt(aRow); nsCOMPtr msgHdr; - if (key == m_cachedMsgKey) - msgHdr = m_cachedHdr; - else - { - rv = GetMsgHdrForViewIndex(aRow, getter_AddRefs(msgHdr)); - if (NS_SUCCEEDED(rv)) - { - m_cachedHdr = msgHdr; - m_cachedMsgKey = key; - } - } - + rv = GetMsgHdrForViewIndex(aRow, getter_AddRefs(msgHdr)); + if (NS_FAILED(rv) || !msgHdr) { ClearHdrCache(); return NS_MSG_INVALID_DBVIEW_INDEX; diff --git a/mailnews/base/src/nsMsgSearchDBView.cpp b/mailnews/base/src/nsMsgSearchDBView.cpp index 261ab805a76..19f560fa87f 100644 --- a/mailnews/base/src/nsMsgSearchDBView.cpp +++ b/mailnews/base/src/nsMsgSearchDBView.cpp @@ -60,9 +60,6 @@ NS_IMETHODIMP nsMsgSearchDBView::Open(nsIMsgFolder *folder, nsMsgViewSortTypeVal m_folders = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); - m_hdrs = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv); - NS_ENSURE_SUCCESS(rv,rv); - m_dbToUseList = do_CreateInstance(NS_SUPPORTSARRAY_CONTRACTID, &rv); NS_ENSURE_SUCCESS(rv, rv); @@ -160,7 +157,6 @@ nsMsgSearchDBView::OnSearchHit(nsIMsgDBHdr* aMsgHdr, nsIMsgFolder *folder) m_folders->AppendElement(supports); nsMsgKey msgKey; PRUint32 msgFlags; - m_hdrs->AppendElement(aMsgHdr); aMsgHdr->GetMessageKey(&msgKey); aMsgHdr->GetFlags(&msgFlags); m_keys.Add(msgKey); @@ -192,7 +188,6 @@ nsMsgSearchDBView::OnNewSearch() m_keys.RemoveAll(); m_levels.RemoveAll(); m_flags.RemoveAll(); - m_hdrs->Clear(); // mSearchResults->Clear(); return NS_OK; @@ -230,7 +225,6 @@ nsresult nsMsgSearchDBView::RemoveByIndex(nsMsgViewIndex index) return NS_MSG_INVALID_DBVIEW_INDEX; m_folders->RemoveElementAt(index); - m_hdrs->RemoveElementAt(index); return nsMsgDBView::RemoveByIndex(index); } @@ -331,7 +325,10 @@ nsMsgSearchDBView::InitializeGlobalsForDeleteAndFile(nsMsgViewIndex *indices, PR nsCOMPtr msgFolder = do_QueryInterface(folderSupports, &rv); if (NS_SUCCEEDED(rv) && msgFolder && msgFolder == curFolder) { - nsCOMPtr hdrSupports = getter_AddRefs(m_hdrs->ElementAt(indices[i])); + nsCOMPtr msgHdr; + rv = GetMsgHdrForViewIndex(indices[i],getter_AddRefs(msgHdr)); + NS_ENSURE_SUCCESS(rv,rv); + nsCOMPtr hdrSupports = do_QueryInterface(msgHdr); msgHdrsForOneFolder->AppendElement(hdrSupports); } } @@ -469,3 +466,4 @@ NS_IMETHODIMP nsMsgSearchDBView::Sort(nsMsgViewSortTypeValue sortType, nsMsgView return rv; } + diff --git a/mailnews/base/src/nsMsgSearchDBView.h b/mailnews/base/src/nsMsgSearchDBView.h index f89725ce073..54575bec50c 100644 --- a/mailnews/base/src/nsMsgSearchDBView.h +++ b/mailnews/base/src/nsMsgSearchDBView.h @@ -59,7 +59,6 @@ protected: nsresult GroupSearchResultsByFolder(); nsCOMPtr m_folders; // maybe we should store ranges, or the actual headers instead. - nsCOMPtr m_hdrs; nsCOMPtr m_hdrsForEachFolder; nsCOMPtr m_copyListenerList; nsCOMPtr m_uniqueFolders;