Skip to content

Commit

Permalink
Bug 459299 - nsNavHistory::SetPageTitleInternal is slow
Browse files Browse the repository at this point in the history
This caches a statement that is created any time a pages title changes.  The
creation of the statement took roughly 66% of the functions execution time
according to shark.
It also removes a transaction that was not needed in this method.
r=dietrich
  • Loading branch information
sdwilsh committed Oct 17, 2008
1 parent b71369c commit 4d5fb2f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
31 changes: 15 additions & 16 deletions toolkit/components/places/src/nsNavHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1337,6 +1337,15 @@ nsNavHistory::InitStatements()
getter_AddRefs(mFoldersWithAnnotationQuery));
NS_ENSURE_SUCCESS(rv, rv);

// mDBSetPlaceTitle
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"UPDATE moz_places_view "
"SET title = ?1 "
"WHERE url = ?2"),
getter_AddRefs(mDBSetPlaceTitle));
NS_ENSURE_SUCCESS(rv, rv);


// mDBVisitsForFrecency
// NOTE: we are not limiting to visits with "visit_type NOT IN (0,4,7)"
// because if we do that, mDBVisitsForFrecency would return no visits
Expand Down Expand Up @@ -6587,8 +6596,6 @@ nsNavHistory::SetPageTitleInternal(nsIURI* aURI, const nsAString& aTitle)
{
nsresult rv;

mozStorageTransaction transaction(mDBConn, PR_TRUE);

// first, make sure the page exists, and fetch the old title (we need the one
// that isn't changing to send notifications)
nsAutoString title;
Expand Down Expand Up @@ -6616,32 +6623,24 @@ nsNavHistory::SetPageTitleInternal(nsIURI* aURI, const nsAString& aTitle)
if ((aTitle.IsVoid() && title.IsVoid()) || aTitle == title)
return NS_OK;

nsCOMPtr<mozIStorageStatement> dbModStatement;
title = aTitle;
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"UPDATE moz_places_view SET title = ?1 WHERE url = ?2"),
getter_AddRefs(dbModStatement));
NS_ENSURE_SUCCESS(rv, rv);

mozStorageStatementScoper scoper(mDBSetPlaceTitle);
// title
if (aTitle.IsVoid())
dbModStatement->BindNullParameter(0);
rv = mDBSetPlaceTitle->BindNullParameter(0);
else
dbModStatement->BindStringParameter(0, StringHead(aTitle, HISTORY_TITLE_LENGTH_MAX));
rv = mDBSetPlaceTitle->BindStringParameter(0, StringHead(aTitle, HISTORY_TITLE_LENGTH_MAX));
NS_ENSURE_SUCCESS(rv, rv);

// url
rv = BindStatementURI(dbModStatement, 1, aURI);
rv = BindStatementURI(mDBSetPlaceTitle, 1, aURI);
NS_ENSURE_SUCCESS(rv, rv);

rv = dbModStatement->Execute();
NS_ENSURE_SUCCESS(rv, rv);
rv = transaction.Commit();
rv = mDBSetPlaceTitle->Execute();
NS_ENSURE_SUCCESS(rv, rv);

// observers (have to check first if it's bookmarked)
ENUMERATE_WEAKARRAY(mObservers, nsINavHistoryObserver,
OnTitleChanged(aURI, title))
OnTitleChanged(aURI, aTitle))

return NS_OK;

Expand Down
1 change: 1 addition & 0 deletions toolkit/components/places/src/nsNavHistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ class nsNavHistory : public nsSupportsWeakReference,
nsCOMPtr<mozIStorageStatement> mDBAddNewPage; // used by InternalAddNewPage
nsCOMPtr<mozIStorageStatement> mDBGetTags; // used by FilterResultSet
nsCOMPtr<mozIStorageStatement> mFoldersWithAnnotationQuery; // used by StartSearch and FilterResultSet
nsCOMPtr<mozIStorageStatement> mDBSetPlaceTitle; // used by SetPageTitleInternal

// these are used by VisitIdToResultNode for making new result nodes from IDs
nsCOMPtr<mozIStorageStatement> mDBVisitToURLResult; // kGetInfoIndex_* results
Expand Down

0 comments on commit 4d5fb2f

Please sign in to comment.