зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1083462 - Remove the bookmarks cache r=mak
This commit is contained in:
Родитель
d2bbb9804e
Коммит
4c199ab4c3
|
@ -20,31 +20,6 @@
|
|||
#include "GeckoProfiler.h"
|
||||
|
||||
#define BOOKMARKS_TO_KEYWORDS_INITIAL_CACHE_LENGTH 32
|
||||
#define RECENT_BOOKMARKS_INITIAL_CACHE_LENGTH 10
|
||||
// Threshold to expire old bookmarks if the initial cache size is exceeded.
|
||||
#define RECENT_BOOKMARKS_THRESHOLD PRTime((int64_t)1 * 60 * PR_USEC_PER_SEC)
|
||||
|
||||
#define BEGIN_CRITICAL_BOOKMARK_CACHE_SECTION(_itemId_) \
|
||||
mUncachableBookmarks.PutEntry(_itemId_); \
|
||||
mRecentBookmarksCache.RemoveEntry(_itemId_)
|
||||
|
||||
#define END_CRITICAL_BOOKMARK_CACHE_SECTION(_itemId_) \
|
||||
MOZ_ASSERT(!mRecentBookmarksCache.GetEntry(_itemId_)); \
|
||||
MOZ_ASSERT(mUncachableBookmarks.GetEntry(_itemId_)); \
|
||||
mUncachableBookmarks.RemoveEntry(_itemId_)
|
||||
|
||||
#define ADD_TO_BOOKMARK_CACHE(_itemId_, _data_) \
|
||||
PR_BEGIN_MACRO \
|
||||
ExpireNonrecentBookmarks(&mRecentBookmarksCache); \
|
||||
if (!mUncachableBookmarks.GetEntry(_itemId_)) { \
|
||||
BookmarkKeyClass* key = mRecentBookmarksCache.PutEntry(_itemId_); \
|
||||
if (key) { \
|
||||
key->bookmark = _data_; \
|
||||
} \
|
||||
} \
|
||||
PR_END_MACRO
|
||||
|
||||
#define TOPIC_PLACES_MAINTENANCE "places-maintenance-finished"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
|
@ -155,46 +130,6 @@ private:
|
|||
DataType mData;
|
||||
};
|
||||
|
||||
static PLDHashOperator
|
||||
ExpireNonrecentBookmarksCallback(BookmarkKeyClass* aKey,
|
||||
void* userArg)
|
||||
{
|
||||
int64_t* threshold = reinterpret_cast<int64_t*>(userArg);
|
||||
if (aKey->creationTime < *threshold) {
|
||||
return PL_DHASH_REMOVE;
|
||||
}
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
static void
|
||||
ExpireNonrecentBookmarks(nsTHashtable<BookmarkKeyClass>* hashTable)
|
||||
{
|
||||
if (hashTable->Count() > RECENT_BOOKMARKS_INITIAL_CACHE_LENGTH) {
|
||||
int64_t threshold = PR_Now() - RECENT_BOOKMARKS_THRESHOLD;
|
||||
(void)hashTable->EnumerateEntries(ExpireNonrecentBookmarksCallback,
|
||||
reinterpret_cast<void*>(&threshold));
|
||||
}
|
||||
}
|
||||
|
||||
static PLDHashOperator
|
||||
ExpireRecentBookmarksByParentCallback(BookmarkKeyClass* aKey,
|
||||
void* userArg)
|
||||
{
|
||||
int64_t* parentId = reinterpret_cast<int64_t*>(userArg);
|
||||
if (aKey->bookmark.parentId == *parentId) {
|
||||
return PL_DHASH_REMOVE;
|
||||
}
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
static void
|
||||
ExpireRecentBookmarksByParent(nsTHashtable<BookmarkKeyClass>* hashTable,
|
||||
int64_t aParentId)
|
||||
{
|
||||
(void)hashTable->EnumerateEntries(ExpireRecentBookmarksByParentCallback,
|
||||
reinterpret_cast<void*>(&aParentId));
|
||||
}
|
||||
|
||||
} // Anonymous namespace.
|
||||
|
||||
|
||||
|
@ -210,8 +145,6 @@ nsNavBookmarks::nsNavBookmarks()
|
|||
, mBatching(false)
|
||||
, mBookmarkToKeywordHash(BOOKMARKS_TO_KEYWORDS_INITIAL_CACHE_LENGTH)
|
||||
, mBookmarkToKeywordHashInitialized(false)
|
||||
, mRecentBookmarksCache(RECENT_BOOKMARKS_INITIAL_CACHE_LENGTH)
|
||||
, mUncachableBookmarks(RECENT_BOOKMARKS_INITIAL_CACHE_LENGTH)
|
||||
{
|
||||
NS_ASSERTION(!gBookmarksService,
|
||||
"Attempting to create two instances of the service!");
|
||||
|
@ -245,7 +178,6 @@ nsNavBookmarks::Init()
|
|||
|
||||
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
|
||||
if (os) {
|
||||
(void)os->AddObserver(this, TOPIC_PLACES_MAINTENANCE, true);
|
||||
(void)os->AddObserver(this, TOPIC_PLACES_SHUTDOWN, true);
|
||||
(void)os->AddObserver(this, TOPIC_PLACES_CONNECTION_CLOSED, true);
|
||||
}
|
||||
|
@ -346,10 +278,6 @@ nsNavBookmarks::AdjustIndices(int64_t aFolderId,
|
|||
NS_ASSERTION(aStartIndex >= 0 && aEndIndex <= INT32_MAX &&
|
||||
aStartIndex <= aEndIndex, "Bad indices");
|
||||
|
||||
// Expire all cached items for this parent, since all positions are going to
|
||||
// change.
|
||||
ExpireRecentBookmarksByParent(&mRecentBookmarksCache, aFolderId);
|
||||
|
||||
nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(
|
||||
"UPDATE moz_bookmarks SET position = position + :delta "
|
||||
"WHERE parent = :parent "
|
||||
|
@ -552,8 +480,6 @@ nsNavBookmarks::InsertBookmarkInDB(int64_t aPlaceId,
|
|||
bookmark.parentGuid = aParentGuid;
|
||||
bookmark.grandParentId = aGrandParentId;
|
||||
|
||||
ADD_TO_BOOKMARK_CACHE(*_itemId, bookmark);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -684,8 +610,6 @@ nsNavBookmarks::RemoveItem(int64_t aItemId)
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
BEGIN_CRITICAL_BOOKMARK_CACHE_SECTION(bookmark.id);
|
||||
|
||||
nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(
|
||||
"DELETE FROM moz_bookmarks WHERE id = :item_id"
|
||||
);
|
||||
|
@ -712,8 +636,6 @@ nsNavBookmarks::RemoveItem(int64_t aItemId)
|
|||
rv = transaction.Commit();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
END_CRITICAL_BOOKMARK_CACHE_SECTION(bookmark.id);
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
if (bookmark.type == TYPE_BOOKMARK) {
|
||||
// If not a tag, recalculate frecency for this entry, since it changed.
|
||||
|
@ -1154,8 +1076,6 @@ nsNavBookmarks::RemoveFolderChildren(int64_t aFolderId)
|
|||
foldersToRemove.Append(',');
|
||||
foldersToRemove.AppendInt(child.id);
|
||||
}
|
||||
|
||||
BEGIN_CRITICAL_BOOKMARK_CACHE_SECTION(child.id);
|
||||
}
|
||||
|
||||
// Delete items from the database now.
|
||||
|
@ -1202,7 +1122,6 @@ nsNavBookmarks::RemoveFolderChildren(int64_t aFolderId)
|
|||
rv = UpdateKeywordsHashForRemovedBookmark(child.id);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
END_CRITICAL_BOOKMARK_CACHE_SECTION(child.id);
|
||||
}
|
||||
|
||||
rv = transaction.Commit();
|
||||
|
@ -1351,8 +1270,6 @@ nsNavBookmarks::MoveItem(int64_t aItemId, int64_t aNewParent, int32_t aIndex)
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
||||
BEGIN_CRITICAL_BOOKMARK_CACHE_SECTION(bookmark.id);
|
||||
|
||||
{
|
||||
// Update parent and position.
|
||||
nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(
|
||||
|
@ -1381,8 +1298,6 @@ nsNavBookmarks::MoveItem(int64_t aItemId, int64_t aNewParent, int32_t aIndex)
|
|||
rv = transaction.Commit();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
END_CRITICAL_BOOKMARK_CACHE_SECTION(bookmark.id);
|
||||
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavBookmarkObserver,
|
||||
OnItemMoved(bookmark.id,
|
||||
|
@ -1401,14 +1316,6 @@ nsresult
|
|||
nsNavBookmarks::FetchItemInfo(int64_t aItemId,
|
||||
BookmarkData& _bookmark)
|
||||
{
|
||||
// Check if the requested id is in the recent cache and avoid the database
|
||||
// lookup if so. Invalidate the cache after getting data if requested.
|
||||
BookmarkKeyClass* key = mRecentBookmarksCache.GetEntry(aItemId);
|
||||
if (key) {
|
||||
_bookmark = key->bookmark;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// LEFT JOIN since not all bookmarks have an associated place.
|
||||
nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(
|
||||
"SELECT b.id, h.url, b.title, b.position, b.fk, b.parent, b.type, "
|
||||
|
@ -1471,8 +1378,6 @@ nsNavBookmarks::FetchItemInfo(int64_t aItemId,
|
|||
_bookmark.grandParentId = -1;
|
||||
}
|
||||
|
||||
ADD_TO_BOOKMARK_CACHE(aItemId, _bookmark);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1507,16 +1412,6 @@ nsNavBookmarks::SetItemDateInternal(enum BookmarkDate aDateType,
|
|||
rv = stmt->Execute();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Update the cache entry, if needed.
|
||||
BookmarkKeyClass* key = mRecentBookmarksCache.GetEntry(aItemId);
|
||||
if (key) {
|
||||
if (aDateType == DATE_ADDED) {
|
||||
key->bookmark.dateAdded = aValue;
|
||||
}
|
||||
// Set lastModified in both cases.
|
||||
key->bookmark.lastModified = aValue;
|
||||
}
|
||||
|
||||
// note, we are not notifying the observers
|
||||
// that the item has changed.
|
||||
|
||||
|
@ -1650,18 +1545,6 @@ nsNavBookmarks::SetItemTitle(int64_t aItemId, const nsACString& aTitle)
|
|||
rv = statement->Execute();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Update the cache entry, if needed.
|
||||
BookmarkKeyClass* key = mRecentBookmarksCache.GetEntry(aItemId);
|
||||
if (key) {
|
||||
if (title.IsVoid()) {
|
||||
key->bookmark.title.SetIsVoid(true);
|
||||
}
|
||||
else {
|
||||
key->bookmark.title.Assign(title);
|
||||
}
|
||||
key->bookmark.lastModified = bookmark.lastModified;
|
||||
}
|
||||
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavBookmarkObserver,
|
||||
OnItemChanged(bookmark.id,
|
||||
|
@ -2109,8 +1992,6 @@ nsNavBookmarks::ChangeBookmarkURI(int64_t aBookmarkId, nsIURI* aNewURI)
|
|||
if (!newPlaceId)
|
||||
return NS_ERROR_INVALID_ARG;
|
||||
|
||||
BEGIN_CRITICAL_BOOKMARK_CACHE_SECTION(bookmark.id);
|
||||
|
||||
nsCOMPtr<mozIStorageStatement> statement = mDB->GetStatement(
|
||||
"UPDATE moz_bookmarks SET fk = :page_id, lastModified = :date "
|
||||
"WHERE id = :item_id "
|
||||
|
@ -2132,8 +2013,6 @@ nsNavBookmarks::ChangeBookmarkURI(int64_t aBookmarkId, nsIURI* aNewURI)
|
|||
rv = transaction.Commit();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
END_CRITICAL_BOOKMARK_CACHE_SECTION(bookmark.id);
|
||||
|
||||
rv = history->UpdateFrecency(newPlaceId);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
|
@ -2345,8 +2224,6 @@ nsNavBookmarks::SetItemIndex(int64_t aItemId, int32_t aNewIndex)
|
|||
// Check the parent's guid is the expected one.
|
||||
MOZ_ASSERT(bookmark.parentGuid == folderGuid);
|
||||
|
||||
BEGIN_CRITICAL_BOOKMARK_CACHE_SECTION(bookmark.id);
|
||||
|
||||
nsCOMPtr<mozIStorageStatement> stmt = mDB->GetStatement(
|
||||
"UPDATE moz_bookmarks SET position = :item_index WHERE id = :item_id"
|
||||
);
|
||||
|
@ -2361,8 +2238,6 @@ nsNavBookmarks::SetItemIndex(int64_t aItemId, int32_t aNewIndex)
|
|||
rv = stmt->Execute();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
END_CRITICAL_BOOKMARK_CACHE_SECTION(bookmark.id);
|
||||
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavBookmarkObserver,
|
||||
OnItemMoved(bookmark.id,
|
||||
|
@ -2495,12 +2370,6 @@ nsNavBookmarks::SetKeywordForBookmark(int64_t aBookmarkId,
|
|||
rv = transaction.Commit();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Update the cache entry, if needed.
|
||||
BookmarkKeyClass* key = mRecentBookmarksCache.GetEntry(aBookmarkId);
|
||||
if (key) {
|
||||
key->bookmark.lastModified = bookmark.lastModified;
|
||||
}
|
||||
|
||||
NOTIFY_OBSERVERS(mCanNotify, mCacheObservers, mObservers,
|
||||
nsINavBookmarkObserver,
|
||||
OnItemChanged(bookmark.id,
|
||||
|
@ -2758,12 +2627,7 @@ nsNavBookmarks::Observe(nsISupports *aSubject, const char *aTopic,
|
|||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "This can only be called on the main thread");
|
||||
|
||||
if (strcmp(aTopic, TOPIC_PLACES_MAINTENANCE) == 0) {
|
||||
// Maintenance can execute direct writes to the database, thus clear all
|
||||
// the cached bookmarks.
|
||||
mRecentBookmarksCache.Clear();
|
||||
}
|
||||
else if (strcmp(aTopic, TOPIC_PLACES_SHUTDOWN) == 0) {
|
||||
if (strcmp(aTopic, TOPIC_PLACES_SHUTDOWN) == 0) {
|
||||
// Stop Observing annotations.
|
||||
nsAnnotationService* annosvc = nsAnnotationService::GetAnnotationService();
|
||||
if (annosvc) {
|
||||
|
|
|
@ -61,24 +61,6 @@ namespace places {
|
|||
typedef void (nsNavBookmarks::*ItemVisitMethod)(const ItemVisitData&);
|
||||
typedef void (nsNavBookmarks::*ItemChangeMethod)(const ItemChangeData&);
|
||||
|
||||
class BookmarkKeyClass : public nsTrimInt64HashKey
|
||||
{
|
||||
public:
|
||||
explicit BookmarkKeyClass(const int64_t* aItemId)
|
||||
: nsTrimInt64HashKey(aItemId)
|
||||
, creationTime(PR_Now())
|
||||
{
|
||||
}
|
||||
BookmarkKeyClass(const BookmarkKeyClass& aOther)
|
||||
: nsTrimInt64HashKey(aOther)
|
||||
, creationTime(PR_Now())
|
||||
{
|
||||
NS_NOTREACHED("Do not call me!");
|
||||
}
|
||||
BookmarkData bookmark;
|
||||
PRTime creationTime;
|
||||
};
|
||||
|
||||
enum BookmarkDate {
|
||||
DATE_ADDED = 0
|
||||
, LAST_MODIFIED
|
||||
|
@ -124,7 +106,6 @@ public:
|
|||
}
|
||||
|
||||
typedef mozilla::places::BookmarkData BookmarkData;
|
||||
typedef mozilla::places::BookmarkKeyClass BookmarkKeyClass;
|
||||
typedef mozilla::places::ItemVisitData ItemVisitData;
|
||||
typedef mozilla::places::ItemChangeData ItemChangeData;
|
||||
typedef mozilla::places::BookmarkStatementId BookmarkStatementId;
|
||||
|
@ -455,18 +436,6 @@ private:
|
|||
* Uri to test.
|
||||
*/
|
||||
nsresult UpdateKeywordsHashForRemovedBookmark(int64_t aItemId);
|
||||
|
||||
/**
|
||||
* Cache for the last fetched BookmarkData entries.
|
||||
* This is used to speed up repeated requests to the same item id.
|
||||
*/
|
||||
nsTHashtable<BookmarkKeyClass> mRecentBookmarksCache;
|
||||
|
||||
/**
|
||||
* Tracks bookmarks in the cache critical path. Items should not be
|
||||
* added to the cache till they are removed from this hash.
|
||||
*/
|
||||
nsTHashtable<nsTrimInt64HashKey> mUncachableBookmarks;
|
||||
};
|
||||
|
||||
#endif // nsNavBookmarks_h_
|
||||
|
|
Загрузка…
Ссылка в новой задаче