From 5ee84fbaf51e3eb80307979ec87aec91bf0bcea3 Mon Sep 17 00:00:00 2001 From: "sspitzer%netscape.com" Date: Tue, 11 May 1999 04:04:10 +0000 Subject: [PATCH] news, like imap and local mail, needs to use the db cache to make sure that when several Open()'s happen, they get the same db object. this fixes the problem where getting new news wouldn't update the db listers (folder pane and thread pane, in this case.) --- mailnews/db/msgdb/src/nsNewsDatabase.cpp | 29 ++++++++++++++++++------ 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/mailnews/db/msgdb/src/nsNewsDatabase.cpp b/mailnews/db/msgdb/src/nsNewsDatabase.cpp index bd01fe0d952b..d3283bc1d4d7 100644 --- a/mailnews/db/msgdb/src/nsNewsDatabase.cpp +++ b/mailnews/db/msgdb/src/nsNewsDatabase.cpp @@ -37,21 +37,30 @@ nsresult nsNewsDatabase::MessageDBOpenUsingURL(const char * groupURL) return NS_OK; } -/* static */ -nsresult nsNewsDatabase::Open(nsFileSpec &newsgroupName, PRBool create, nsIMsgDatabase** pMessageDB, PRBool upgrading /*=PR_FALSE*/) +NS_IMETHODIMP nsNewsDatabase::Open(nsFileSpec &newsgroupName, PRBool create, nsIMsgDatabase** pMessageDB, PRBool upgrading /*=PR_FALSE*/) { nsNewsDatabase *newsDB; nsNewsSummarySpec summarySpec(newsgroupName); nsresult err = NS_OK; #ifdef DEBUG_sspitzer - printf("nsNewsDatabase::Open(%s, %s, %p, %s) -> %s\n", + printf("nsNewsDatabase::Open(%s, %s, %p, %s) -> %s\n", (const char*)newsgroupName, create ? "TRUE":"FALSE", pMessageDB, upgrading ? "TRUE":"FALSE", (const char*)newsgroupName); #endif + nsFileSpec dbPath(summarySpec); + *pMessageDB = nsnull; + newsDB = (nsNewsDatabase *) FindInCache(dbPath); + if (newsDB) { + *pMessageDB = newsDB; + //FindInCache does the AddRef'ing + //newsDB->AddRef(); + return(NS_OK); + } + newsDB = new nsNewsDatabase(); if (!newsDB) { @@ -69,19 +78,25 @@ nsresult nsNewsDatabase::Open(nsFileSpec &newsgroupName, PRBool create, nsIMsgDa #ifdef DEBUG_sspitzer printf("newsDB->OpenMDB succeeded!\n"); #endif - *pMessageDB = newsDB; + *pMessageDB = newsDB; + if (newsDB) { + GetDBCache()->AppendElement(newsDB); + } } -#ifdef DEBUG_sspitzer else { +#ifdef DEBUG_sspitzer printf("newsDB->OpenMDB failed!\n"); +#endif *pMessageDB = nsnull; - delete newsDB; + if (newsDB) { + delete newsDB; + } newsDB = nsnull; } -#endif return err; } + nsresult nsNewsDatabase::Close(PRBool forceCommit) { return nsMsgDatabase::Close(forceCommit);