Skip to content

Commit

Permalink
Bug 318546 r=bryner Preliminary transition support and precompiled st…
Browse files Browse the repository at this point in the history
…atements for adding entries (should be faster).
  • Loading branch information
brettw%gmail.com committed Dec 14, 2005
1 parent f204d22 commit 7d3f232
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 20 deletions.
69 changes: 51 additions & 18 deletions browser/components/places/src/nsNavHistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,23 @@ nsNavHistory::InitDB()
getter_AddRefs(mDBFullAutoComplete));
NS_ENSURE_SUCCESS(rv, rv);

// mDBRecentVisitOfURL
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"SELECT v.visit_id "
"FROM moz_history h JOIN moz_historyvisit v ON h.id = v.page_id "
"WHERE h.url = ?1 "
"ORDER BY v.visit_date DESC "
"LIMIT 1"),
getter_AddRefs(mDBRecentVisitOfURL));
NS_ENSURE_SUCCESS(rv, rv);

// mDBInsertVisit
rv = mDBConn->CreateStatement(NS_LITERAL_CSTRING(
"INSERT INTO moz_historyvisit "
"(from_visit, page_id, visit_date, visit_type, session) "
"VALUES (?1, ?2, ?3, ?4, ?5)"),
getter_AddRefs(mDBInsertVisit));
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}

Expand Down Expand Up @@ -581,7 +598,7 @@ nsNavHistory::SaveCollapseItem(const nsAString& aTitle)
// added to the history.

nsresult
nsNavHistory::InternalAdd(nsIURI* aURI, PRInt64 aSessionID,
nsNavHistory::InternalAdd(nsIURI* aURI, nsIURI* aReferrer, PRInt64 aSessionID,
PRUint32 aTransitionType, const PRUnichar* aTitle,
PRTime aVisitDate, PRBool aRedirect,
PRBool aToplevel, PRInt64* aPageID)
Expand Down Expand Up @@ -686,7 +703,7 @@ nsNavHistory::InternalAdd(nsIURI* aURI, PRInt64 aSessionID,
NS_ENSURE_SUCCESS(rv, rv);
}

rv = AddVisit(0, pageID, aVisitDate, aTransitionType, aSessionID);
rv = AddVisit(aReferrer, pageID, aVisitDate, aTransitionType, aSessionID);

if (aPageID)
*aPageID = pageID;
Expand Down Expand Up @@ -784,31 +801,47 @@ nsNavHistory::InternalAddNewPage(nsIURI* aURI, const PRUnichar* aTitle,
// nsNavHistory::AddVisit
//
// Just a wrapper for inserting a new visit in the DB.
//
// If you give it a referrer, it will try to find a "good" visit to attach
// as the created visit's source. Unfortunately, we can't track where links
// come from precisely, so we find the most recent visit for the referring
// page and use it as the parent. This will get messed up if one page is
// open in more than one tab/window at once, but should be good enough for
// most cases.

nsresult nsNavHistory::AddVisit(PRInt64 aFromStep, PRInt64 aPageID,
nsresult nsNavHistory::AddVisit(nsIURI* aReferrer, PRInt64 aPageID,
PRTime aTime, PRInt32 aTransitionType,
PRInt64 aSessionID)
{
nsCOMPtr<mozIStorageStatement> dbInsertStatement;
nsresult rv = mDBConn->CreateStatement(
NS_LITERAL_CSTRING("INSERT INTO moz_historyvisit (from_visit, page_id, visit_date, visit_type, session) VALUES ( ?1, ?2, ?3, ?4, ?5 )"),
getter_AddRefs(dbInsertStatement));
NS_ENSURE_SUCCESS(rv, rv);
nsresult rv;
PRInt64 fromStep = 0;
if (aReferrer) {
mozStorageStatementScoper scoper(mDBRecentVisitOfURL);
rv = BindStatementURI(mDBRecentVisitOfURL, 0, aReferrer);
NS_ENSURE_SUCCESS(rv, rv);

PRBool hasMore;
rv = mDBRecentVisitOfURL->ExecuteStep(&hasMore);
NS_ENSURE_SUCCESS(rv, rv);
if (hasMore)
fromStep = mDBRecentVisitOfURL->AsInt64(0);
}

rv = dbInsertStatement->BindInt64Parameter(0, aFromStep);
mozStorageStatementScoper scoper(mDBInsertVisit);

rv = mDBInsertVisit->BindInt64Parameter(0, fromStep);
NS_ENSURE_SUCCESS(rv, rv);
rv = dbInsertStatement->BindInt64Parameter(1, aPageID);
rv = mDBInsertVisit->BindInt64Parameter(1, aPageID);
NS_ENSURE_SUCCESS(rv, rv);
rv = dbInsertStatement->BindInt64Parameter(2, aTime);
rv = mDBInsertVisit->BindInt64Parameter(2, aTime);
NS_ENSURE_SUCCESS(rv, rv);
rv = dbInsertStatement->BindInt32Parameter(3, aTransitionType);
rv = mDBInsertVisit->BindInt32Parameter(3, aTransitionType);
NS_ENSURE_SUCCESS(rv, rv);
rv = dbInsertStatement->BindInt64Parameter(4, aSessionID);
rv = mDBInsertVisit->BindInt64Parameter(4, aSessionID);
NS_ENSURE_SUCCESS(rv, rv);

rv = dbInsertStatement->Execute(); // should reset the statement
rv = mDBInsertVisit->Execute();
NS_ENSURE_SUCCESS(rv, rv);

return NS_OK;
}

Expand Down Expand Up @@ -1457,7 +1490,7 @@ nsNavHistory::AddPageWithDetails(nsIURI *aURI, const PRUnichar *aTitle,
PRInt64 aLastVisited)
{
PRInt64 pageid;
nsresult rv = InternalAdd(aURI, 0, 0, aTitle, aLastVisited,
nsresult rv = InternalAdd(aURI, nsnull, 0, 0, aTitle, aLastVisited,
PR_FALSE, PR_TRUE, &pageid);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
Expand Down Expand Up @@ -1933,8 +1966,8 @@ nsNavHistory::AddURI(nsIURI *aURI, PRBool aRedirect,
// add to main DB
PRInt64 pageid = 0;
PRTime now = GetNow();
nsresult rv = InternalAdd(aURI, 0, 0, nsnull, now, aRedirect, aToplevel,
&pageid);
nsresult rv = InternalAdd(aURI, aReferrer, 0, 0, nsnull, now,
aRedirect, aToplevel, &pageid);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
}
Expand Down
7 changes: 5 additions & 2 deletions browser/components/places/src/nsNavHistory.h
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,9 @@ class nsNavHistory : public nsSupportsWeakReference,
static const PRInt32 kAutoCompleteIndex_VisitCount;
static const PRInt32 kAutoCompleteIndex_Typed;

nsCOMPtr<mozIStorageStatement> mDBRecentVisitOfURL; // converts URL into most recent visit ID
nsCOMPtr<mozIStorageStatement> mDBInsertVisit; // used by AddVisit

nsresult InitDB();

// this is the cache DB in memory used for storing visited URLs
Expand All @@ -593,14 +596,14 @@ class nsNavHistory : public nsSupportsWeakReference,

nsresult InitMemDB();

nsresult InternalAdd(nsIURI* aURI, PRInt64 aSessionID,
nsresult InternalAdd(nsIURI* aURI, nsIURI* aReferrer, PRInt64 aSessionID,
PRUint32 aTransitionType, const PRUnichar* aTitle,
PRTime aVisitDate, PRBool aRedirect,
PRBool aToplevel, PRInt64* aPageID);
nsresult InternalAddNewPage(nsIURI* aURI, const PRUnichar* aTitle,
PRBool aHidden, PRBool aTyped,
PRInt32 aVisitCount, PRInt64* aPageID);
nsresult AddVisit(PRInt64 aFromStep, PRInt64 aPageID, PRTime aTime,
nsresult AddVisit(nsIURI* aReferrer, PRInt64 aPageID, PRTime aTime,
PRInt32 aTransitionType, PRInt64 aSessionID);
PRBool IsURIStringVisited(const nsACString& url);
nsresult VacuumDB(PRTime aTimeAgo, PRBool aCompress);
Expand Down

0 comments on commit 7d3f232

Please sign in to comment.