From af6cbfea6dc31a8922c27ee0ed6235160e565ba2 Mon Sep 17 00:00:00 2001 From: "bienvenu%netscape.com" Date: Sat, 17 Jul 1999 20:33:15 +0000 Subject: [PATCH] more work on folder cache git-svn-id: svn://10.0.0.236/trunk@39902 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/mailnews/base/public/nsIMsgFolder.idl | 4 +- .../mailnews/base/src/nsMsgImapMailFolder.cpp | 2 +- mozilla/mailnews/base/util/nsMsgDBFolder.cpp | 47 +++++++++++++++++-- mozilla/mailnews/base/util/nsMsgDBFolder.h | 3 +- mozilla/mailnews/base/util/nsMsgFolder.cpp | 4 +- mozilla/mailnews/base/util/nsMsgFolder.h | 2 +- .../base/util/nsMsgIncomingServer.cpp | 38 ++------------- .../mailnews/imap/src/nsImapMailFolder.cpp | 8 ++-- mozilla/mailnews/imap/src/nsImapMailFolder.h | 2 +- .../mailnews/local/src/nsLocalMailFolder.cpp | 8 ++-- .../mailnews/local/src/nsLocalMailFolder.h | 2 +- mozilla/mailnews/news/src/nsNewsFolder.cpp | 6 +-- mozilla/mailnews/news/src/nsNewsFolder.h | 2 +- 13 files changed, 70 insertions(+), 58 deletions(-) diff --git a/mozilla/mailnews/base/public/nsIMsgFolder.idl b/mozilla/mailnews/base/public/nsIMsgFolder.idl index c8ad32e7506..76498a96402 100644 --- a/mozilla/mailnews/base/public/nsIMsgFolder.idl +++ b/mozilla/mailnews/base/public/nsIMsgFolder.idl @@ -83,7 +83,7 @@ interface nsIMsgFolder : nsIFolder { attribute unsigned long depth; - void UpdateSummaryTotals(); + void UpdateSummaryTotals(in boolean force); void SummaryChanged(); long GetNumUnread(in boolean deep); long GetTotalMessages(in boolean deep); @@ -143,7 +143,7 @@ interface nsIMsgFolder : nsIFolder { nsIMessage CreateMessageFromMsgDBHdr(in nsIMsgDBHdr msgDBHdr); void GetNewMessages(); - void WriteToFolderCache(in nsIMsgFolderCacheElement folderCacheElem); + void WriteToFolderCache(in nsIMsgFolderCache folderCache); attribute wstring charset; attribute unsigned long BiffState; attribute long NumNewMessages; diff --git a/mozilla/mailnews/base/src/nsMsgImapMailFolder.cpp b/mozilla/mailnews/base/src/nsMsgImapMailFolder.cpp index d90aefc6674..dc3c7c8be97 100644 --- a/mozilla/mailnews/base/src/nsMsgImapMailFolder.cpp +++ b/mozilla/mailnews/base/src/nsMsgImapMailFolder.cpp @@ -150,7 +150,7 @@ NS_IMETHODIMP nsMsgImapMailFolder::GetName(PRUnichar** name) return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP nsMsgImapMailFolder::UpdateSummaryTotals() +NS_IMETHODIMP nsMsgImapMailFolder::UpdateSummaryTotals(PRBool force) { //We need to read this info from the database diff --git a/mozilla/mailnews/base/util/nsMsgDBFolder.cpp b/mozilla/mailnews/base/util/nsMsgDBFolder.cpp index 4e4261e57ef..193e5e8e28e 100644 --- a/mozilla/mailnews/base/util/nsMsgDBFolder.cpp +++ b/mozilla/mailnews/base/util/nsMsgDBFolder.cpp @@ -280,7 +280,7 @@ NS_IMETHODIMP nsMsgDBFolder::OnKeyChange(nsMsgKey aKeyChanged, PRUint32 aOldFlag { SendFlagNotifications(msgSupports, aOldFlags, aNewFlags); } - UpdateSummaryTotals(); + UpdateSummaryTotals(PR_TRUE); } } return NS_OK; @@ -302,7 +302,7 @@ NS_IMETHODIMP nsMsgDBFolder::OnKeyDeleted(nsMsgKey aKeyChanged, PRInt32 aFlags, { NotifyItemDeleted(msgSupports); } - UpdateSummaryTotals(); + UpdateSummaryTotals(PR_TRUE); } } @@ -326,7 +326,7 @@ NS_IMETHODIMP nsMsgDBFolder::OnKeyAdded(nsMsgKey aKeyChanged, PRInt32 aFlags, { NotifyItemAdded(msgSupports); } - // UpdateSummaryTotals(); + // UpdateSummaryTotals(PR_TRUE); } } return NS_OK; @@ -361,7 +361,46 @@ nsresult nsMsgDBFolder::ReadFromFolderCache(nsIMsgFolderCacheElement *element) return rv; } -NS_IMETHODIMP nsMsgDBFolder::WriteToFolderCache(nsIMsgFolderCacheElement *element) +NS_IMETHODIMP nsMsgDBFolder::WriteToFolderCache(nsIMsgFolderCache *folderCache) +{ + nsCOMPtr aEnumerator; + + nsresult rv = GetSubFolders(getter_AddRefs(aEnumerator)); + if(NS_FAILED(rv)) + return rv; + + char *uri = nsnull; + rv = GetURI(&uri); + + if (folderCache) + { + nsCOMPtr cacheElement; + rv = folderCache->GetCacheElement(uri, PR_TRUE, getter_AddRefs(cacheElement)); + if (NS_SUCCEEDED(rv) && cacheElement) + rv = WriteToFolderCacheElem(cacheElement); + } + PR_FREEIF(uri); + + + nsCOMPtr aItem; + + rv = aEnumerator->First(); + while(NS_SUCCEEDED(rv)) + { + rv = aEnumerator->CurrentItem(getter_AddRefs(aItem)); + if (NS_FAILED(rv)) break; + nsCOMPtr aMsgFolder(do_QueryInterface(aItem, &rv)); + if (NS_SUCCEEDED(rv)) + { + if (folderCache) + rv = aMsgFolder->WriteToFolderCache(folderCache); + } + rv = aEnumerator->Next(); + } + return rv; +} + +NS_IMETHODIMP nsMsgDBFolder::WriteToFolderCacheElem(nsIMsgFolderCacheElement *element) { nsresult rv = NS_OK; diff --git a/mozilla/mailnews/base/util/nsMsgDBFolder.h b/mozilla/mailnews/base/util/nsMsgDBFolder.h index 2c323156ff7..8e81444e65d 100644 --- a/mozilla/mailnews/base/util/nsMsgDBFolder.h +++ b/mozilla/mailnews/base/util/nsMsgDBFolder.h @@ -57,7 +57,8 @@ public: NS_DECL_ISUPPORTS_INHERITED - NS_IMETHOD WriteToFolderCache(nsIMsgFolderCacheElement *element); + NS_IMETHOD WriteToFolderCache(nsIMsgFolderCache *folderCache); + NS_IMETHOD WriteToFolderCacheElem(nsIMsgFolderCacheElement *element); protected: virtual nsresult ReadDBFolderInfo(PRBool force); diff --git a/mozilla/mailnews/base/util/nsMsgFolder.cpp b/mozilla/mailnews/base/util/nsMsgFolder.cpp index f365dd58cc9..4ec17e8c6d9 100644 --- a/mozilla/mailnews/base/util/nsMsgFolder.cpp +++ b/mozilla/mailnews/base/util/nsMsgFolder.cpp @@ -708,7 +708,7 @@ NS_IMETHODIMP nsMsgFolder::SetDepth(PRUint32 depth) return NS_OK; } -NS_IMETHODIMP nsMsgFolder::UpdateSummaryTotals() +NS_IMETHODIMP nsMsgFolder::UpdateSummaryTotals(PRBool /* force */) { //We don't support this return NS_OK; @@ -716,7 +716,7 @@ NS_IMETHODIMP nsMsgFolder::UpdateSummaryTotals() NS_IMETHODIMP nsMsgFolder::SummaryChanged() { - UpdateSummaryTotals(); + UpdateSummaryTotals(PR_FALSE); #ifdef HAVE_MASTER if (mMaster) mMaster->BroadcastFolderChanged(this); diff --git a/mozilla/mailnews/base/util/nsMsgFolder.h b/mozilla/mailnews/base/util/nsMsgFolder.h index 056d605babf..d6bbb1c8158 100644 --- a/mozilla/mailnews/base/util/nsMsgFolder.h +++ b/mozilla/mailnews/base/util/nsMsgFolder.h @@ -150,7 +150,7 @@ public: // updates num messages and num unread - should be pure virtual // when I get around to implementing in all subclasses? - NS_IMETHOD UpdateSummaryTotals(); + NS_IMETHOD UpdateSummaryTotals(PRBool force); NS_IMETHOD SummaryChanged(); NS_IMETHOD GetNumUnread(PRBool deep, PRInt32 *numUnread); // How many unread messages in this folder. NS_IMETHOD GetTotalMessages(PRBool deep, PRInt32 *totalMessages); // Total number of messages in this folder. diff --git a/mozilla/mailnews/base/util/nsMsgIncomingServer.cpp b/mozilla/mailnews/base/util/nsMsgIncomingServer.cpp index f95cf7c7311..836070ea0e5 100644 --- a/mozilla/mailnews/base/util/nsMsgIncomingServer.cpp +++ b/mozilla/mailnews/base/util/nsMsgIncomingServer.cpp @@ -100,42 +100,14 @@ nsMsgIncomingServer::PerformBiff() NS_IMETHODIMP nsMsgIncomingServer::WriteToFolderCache(nsIMsgFolderCache *folderCache) { + nsresult rv = NS_OK; if (m_rootFolder) { - nsCOMPtr aEnumerator; - - nsresult rv = m_rootFolder->GetSubFolders(getter_AddRefs(aEnumerator)); - if(NS_FAILED(rv)) return rv; - - nsCOMPtr aItem; - nsCOMPtr trashFolder; - - rv = aEnumerator->First(); - while(NS_SUCCEEDED(rv)) - { - rv = aEnumerator->CurrentItem(getter_AddRefs(aItem)); - if (NS_FAILED(rv)) break; - nsCOMPtr aMsgFolder(do_QueryInterface(aItem, &rv)); - if (NS_SUCCEEDED(rv)) - { - char *uri = nsnull; - rv = aMsgFolder->GetURI(&uri); - if (NS_FAILED(rv)) - break; - - if (folderCache) - { - nsCOMPtr cacheElement; - rv = folderCache->GetCacheElement(uri, PR_TRUE, getter_AddRefs(cacheElement)); - if (NS_SUCCEEDED(rv) && cacheElement) - rv = aMsgFolder->WriteToFolderCache(cacheElement); - } - PR_FREEIF(uri); - } - rv = aEnumerator->Next(); - } + nsCOMPtr msgFolder = do_QueryInterface(m_rootFolder, &rv); + if (NS_SUCCEEDED(rv) && msgFolder) + rv = msgFolder->WriteToFolderCache(folderCache); } - return NS_OK; + return rv; } char * diff --git a/mozilla/mailnews/imap/src/nsImapMailFolder.cpp b/mozilla/mailnews/imap/src/nsImapMailFolder.cpp index a641767b02f..0e7bcff702a 100644 --- a/mozilla/mailnews/imap/src/nsImapMailFolder.cpp +++ b/mozilla/mailnews/imap/src/nsImapMailFolder.cpp @@ -364,7 +364,7 @@ NS_IMETHODIMP nsImapMailFolder::GetSubFolders(nsIEnumerator* *result) } else { - UpdateSummaryTotals(); + UpdateSummaryTotals(PR_FALSE); // Look for a directory for this mail folder, and recurse into it. // e.g. if the folder is "inbox", look for "inbox.sbd". #if 0 @@ -429,7 +429,7 @@ nsresult nsImapMailFolder::GetDatabase() else { //Otherwise we have a valid database so lets extract necessary info. - UpdateSummaryTotals(); + UpdateSummaryTotals(PR_FALSE); } } else @@ -679,7 +679,7 @@ NS_IMETHODIMP nsImapMailFolder::BuildFolderURL(char **url) return rv; } -NS_IMETHODIMP nsImapMailFolder::UpdateSummaryTotals() +NS_IMETHODIMP nsImapMailFolder::UpdateSummaryTotals(PRBool force) { // could we move this into nsMsgDBFolder, or do we need to deal // with the pending imap counts? @@ -688,7 +688,7 @@ NS_IMETHODIMP nsImapMailFolder::UpdateSummaryTotals() PRInt32 oldUnreadMessages = mNumUnreadMessages; PRInt32 oldTotalMessages = mNumTotalMessages; //We need to read this info from the database - ReadDBFolderInfo(PR_TRUE); + ReadDBFolderInfo(force); // If we asked, but didn't get any, stop asking if (mNumUnreadMessages == -1) diff --git a/mozilla/mailnews/imap/src/nsImapMailFolder.h b/mozilla/mailnews/imap/src/nsImapMailFolder.h index dfa572b1c4e..d18dd06c2c2 100644 --- a/mozilla/mailnews/imap/src/nsImapMailFolder.h +++ b/mozilla/mailnews/imap/src/nsImapMailFolder.h @@ -112,7 +112,7 @@ public: NS_IMETHOD BuildFolderURL(char **url); - NS_IMETHOD UpdateSummaryTotals() ; + NS_IMETHOD UpdateSummaryTotals(PRBool force) ; NS_IMETHOD GetExpungedBytesCount(PRUint32 *count); NS_IMETHOD GetDeletable (PRBool *deletable); diff --git a/mozilla/mailnews/local/src/nsLocalMailFolder.cpp b/mozilla/mailnews/local/src/nsLocalMailFolder.cpp index e26a25e8989..6530fa0e3da 100644 --- a/mozilla/mailnews/local/src/nsLocalMailFolder.cpp +++ b/mozilla/mailnews/local/src/nsLocalMailFolder.cpp @@ -355,7 +355,7 @@ nsMsgLocalMailFolder::GetSubFolders(nsIEnumerator* *result) SetFlag(newFlags); rv = CreateSubFolders(path); } - UpdateSummaryTotals(); + UpdateSummaryTotals(PR_FALSE); if (NS_FAILED(rv)) return rv; mInitialized = PR_TRUE; // XXX do this on failure too? @@ -433,7 +433,7 @@ nsresult nsMsgLocalMailFolder::GetDatabase() else { //Otherwise we have a valid database so lets extract necessary info. - UpdateSummaryTotals(); + UpdateSummaryTotals(PR_FALSE); } } } @@ -835,12 +835,12 @@ nsresult nsMsgLocalMailFolder::GetDBFolderInfoAndDB(nsIDBFolderInfo **folderInf return openErr; } -NS_IMETHODIMP nsMsgLocalMailFolder::UpdateSummaryTotals() +NS_IMETHODIMP nsMsgLocalMailFolder::UpdateSummaryTotals(PRBool force) { PRInt32 oldUnreadMessages = mNumUnreadMessages; PRInt32 oldTotalMessages = mNumTotalMessages; //We need to read this info from the database - ReadDBFolderInfo(PR_TRUE); + ReadDBFolderInfo(force); // If we asked, but didn't get any, stop asking if (mNumUnreadMessages == -1) diff --git a/mozilla/mailnews/local/src/nsLocalMailFolder.h b/mozilla/mailnews/local/src/nsLocalMailFolder.h index fb7cad04559..3092d878996 100644 --- a/mozilla/mailnews/local/src/nsLocalMailFolder.h +++ b/mozilla/mailnews/local/src/nsLocalMailFolder.h @@ -97,7 +97,7 @@ public: NS_IMETHOD BuildFolderURL(char **url); - NS_IMETHOD UpdateSummaryTotals() ; + NS_IMETHOD UpdateSummaryTotals(PRBool force) ; NS_IMETHOD GetExpungedBytesCount(PRUint32 *count); NS_IMETHOD GetDeletable (PRBool *deletable); diff --git a/mozilla/mailnews/news/src/nsNewsFolder.cpp b/mozilla/mailnews/news/src/nsNewsFolder.cpp index 1186d7a4650..8afb28edb7c 100644 --- a/mozilla/mailnews/news/src/nsNewsFolder.cpp +++ b/mozilla/mailnews/news/src/nsNewsFolder.cpp @@ -557,7 +557,7 @@ nsresult nsMsgNewsFolder::GetDatabase() rv = mDatabase->AddListener(this); if (NS_FAILED(rv)) return rv; - rv = UpdateSummaryTotals(); + rv = UpdateSummaryTotals(PR_TRUE); if (NS_FAILED(rv)) return rv; } } @@ -1008,7 +1008,7 @@ nsresult nsMsgNewsFolder::GetDBFolderInfoAndDB(nsIDBFolderInfo **folderInfo, ns return openErr; } -NS_IMETHODIMP nsMsgNewsFolder::UpdateSummaryTotals() +NS_IMETHODIMP nsMsgNewsFolder::UpdateSummaryTotals(PRBool force) { #ifdef DEBUG_NEWS printf("nsMsgNewsFolder::UpdateSummaryTotals(%s)\n",mURI); @@ -1017,7 +1017,7 @@ NS_IMETHODIMP nsMsgNewsFolder::UpdateSummaryTotals() PRInt32 oldUnreadMessages = mNumUnreadMessages; PRInt32 oldTotalMessages = mNumTotalMessages; //We need to read this info from the database - ReadDBFolderInfo(PR_TRUE); + ReadDBFolderInfo(force); // If we asked, but didn't get any, stop asking if (mNumUnreadMessages == -1) diff --git a/mozilla/mailnews/news/src/nsNewsFolder.h b/mozilla/mailnews/news/src/nsNewsFolder.h index 284568e91b0..7b61bf190c0 100644 --- a/mozilla/mailnews/news/src/nsNewsFolder.h +++ b/mozilla/mailnews/news/src/nsNewsFolder.h @@ -69,7 +69,7 @@ public: NS_IMETHOD BuildFolderURL(char **url); - NS_IMETHOD UpdateSummaryTotals() ; + NS_IMETHOD UpdateSummaryTotals(PRBool force) ; NS_IMETHOD GetExpungedBytesCount(PRUint32 *count); NS_IMETHOD GetDeletable (PRBool *deletable);