Bug 385876 - DM should cache the query that nsDownload::UpdateDB uses. Patch by Ryan Jones <sciguyryan@gmail.com>. r=sdwilsh

This commit is contained in:
sdwilsh%shawnwilsher.com 2007-07-02 17:29:59 +00:00
Родитель a54331573e
Коммит a893ba34e2
2 изменённых файлов: 12 добавлений и 10 удалений

Просмотреть файл

@ -63,7 +63,6 @@
#include "nsEmbedCID.h" #include "nsEmbedCID.h"
#include "mozStorageCID.h" #include "mozStorageCID.h"
#include "mozIStorageService.h" #include "mozIStorageService.h"
#include "mozIStorageStatement.h"
#include "mozStorageHelper.h" #include "mozStorageHelper.h"
#include "nsIMutableArray.h" #include "nsIMutableArray.h"
#include "nsIAlertsService.h" #include "nsIAlertsService.h"
@ -436,6 +435,13 @@ nsDownloadManager::Init()
mObserverService->AddObserver(this, "quit-application-requested", PR_FALSE); mObserverService->AddObserver(this, "quit-application-requested", PR_FALSE);
mObserverService->AddObserver(this, "offline-requested", PR_FALSE); mObserverService->AddObserver(this, "offline-requested", PR_FALSE);
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"UPDATE moz_downloads "
"SET name = ?1, source = ?2, target = ?3, startTime = ?4, endTime = ?5,"
"state = ?6 "
"WHERE id = ?7"), getter_AddRefs(mUpdateDownloadStatement));
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK; return NS_OK;
} }
@ -1581,16 +1587,10 @@ nsDownload::UpdateDB()
NS_ASSERTION(mID, "Download ID is stored as zero. This is bad!"); NS_ASSERTION(mID, "Download ID is stored as zero. This is bad!");
NS_ASSERTION(mDownloadManager, "Egads! We have no download manager!"); NS_ASSERTION(mDownloadManager, "Egads! We have no download manager!");
nsCOMPtr<mozIStorageStatement> stmt; mozIStorageStatement *stmt = mDownloadManager->mUpdateDownloadStatement;
nsresult rv = mDownloadManager->mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"UPDATE moz_downloads "
"SET name = ?1, source = ?2, target = ?3, startTime = ?4, endTime = ?5,"
"state = ?6 "
"WHERE id = ?7"), getter_AddRefs(stmt));
NS_ENSURE_SUCCESS(rv, rv);
// name // name
rv = stmt->BindStringParameter(0, mDisplayName); nsresult rv = stmt->BindStringParameter(0, mDisplayName);
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
// source // source

Просмотреть файл

@ -60,6 +60,7 @@
#include "nsIMIMEInfo.h" #include "nsIMIMEInfo.h"
#include "nsITimer.h" #include "nsITimer.h"
#include "mozIStorageConnection.h" #include "mozIStorageConnection.h"
#include "mozIStorageStatement.h"
#include "nsISupportsArray.h" #include "nsISupportsArray.h"
#include "nsCOMArray.h" #include "nsCOMArray.h"
#include "nsArrayEnumerator.h" #include "nsArrayEnumerator.h"
@ -184,6 +185,7 @@ private:
nsCOMPtr<mozIStorageConnection> mDBConn; nsCOMPtr<mozIStorageConnection> mDBConn;
nsCOMArray<nsDownload> mCurrentDownloads; nsCOMArray<nsDownload> mCurrentDownloads;
nsCOMPtr<nsIObserverService> mObserverService; nsCOMPtr<nsIObserverService> mObserverService;
nsCOMPtr<mozIStorageStatement> mUpdateDownloadStatement;
friend class nsDownload; friend class nsDownload;
}; };