fix for bug #397527: append folder and all ancestors to the include / exclude folder array in nsNavHistory::FilterResultSet(), to save repeated queries r=dietrich, a=mconnor

This commit is contained in:
sspitzer@mozilla.org 2007-09-27 10:08:15 -07:00
parent b3112de226
commit 9c0f9c251e

View File

@ -4199,22 +4199,28 @@ nsNavHistory::FilterResultSet(nsNavHistoryQueryResultNode* aQueryNode,
// check ancestors
PRInt64 ancestor = parentId, lastAncestor;
PRBool belongs = PR_FALSE;
nsTArray<PRInt64> ancestorFolders;
while (!belongs) {
// Avoid using |ancestor| itself if GetFolderIdForItem failed.
lastAncestor = ancestor;
ancestorFolders.AppendElement(ancestor);
// GetFolderIdForItems throws when called for the places-root
if (NS_FAILED(bookmarks->GetFolderIdForItem(ancestor,&ancestor))) {
break;
} else if (excludeFolders[queryIndex]->IndexOf(ancestor) != -1) {
break;
} else if (includeFolders[queryIndex]->IndexOf(ancestor) != -1) {
belongs = PR_TRUE;
}
}
// if the parentId or any of its ancestors "belong",
// include all of them. otherwise, exclude all of them.
if (belongs) {
includeFolders[queryIndex]->AppendElement(lastAncestor);
includeFolders[queryIndex]->AppendElements(ancestorFolders);
} else {
excludeFolders[queryIndex]->AppendElement(lastAncestor);
excludeFolders[queryIndex]->AppendElements(ancestorFolders);
continue;
}
}