Detect dupe separators by identifying them by their position and generate the lookup lazily with the folder/title mapping for now.

This commit is contained in:
Edward Lee 2009-09-08 23:33:58 -07:00
parent 258a985cee
commit 87de5afcd8
2 changed files with 35 additions and 8 deletions

View File

@ -99,20 +99,40 @@ BookmarksEngine.prototype = {
_syncStartup: function _syncStart() {
SyncEngine.prototype._syncStartup.call(this);
// Lazily create a mapping of folder titles to ids if necessary
this.__defineGetter__("_folderTitles", function() {
// Lazily create a mapping of folder titles and separator positions to GUID
let lazyMap = function() {
delete this._folderTitles;
delete this._separatorPos;
let folderTitles = {};
let separatorPos = {};
for (let guid in this._store.getAllIDs()) {
let id = idForGUID(guid);
if (Svc.Bookmark.getItemType(id) != Svc.Bookmark.TYPE_FOLDER)
continue;
folderTitles[Svc.Bookmark.getItemTitle(id)] = guid;
switch (Svc.Bookmark.getItemType(id)) {
case Svc.Bookmark.TYPE_FOLDER:
// Map the folder name to GUID
folderTitles[Svc.Bookmark.getItemTitle(id)] = guid;
break;
case Svc.Bookmark.TYPE_SEPARATOR:
// Map the separator position and parent position to GUID
let parent = Svc.Bookmark.getFolderIdForItem(id);
let pos = [id, parent].map(Svc.Bookmark.getItemIndex);
separatorPos[pos] = guid;
break;
}
}
return this._folderTitles = folderTitles;
});
this._folderTitles = folderTitles;
this._separatorPos = separatorPos;
};
// Make the getters that lazily build the mapping
["_folderTitles", "_separatorPos"].forEach(function(lazy) {
this.__defineGetter__(lazy, function() {
lazyMap.call(this);
return this[lazy];
});
}, this);
},
_syncFinish: function _syncFinish() {
@ -134,6 +154,8 @@ BookmarksEngine.prototype = {
case "folder":
case "livemark":
return this._folderTitles[item.title];
case "separator":
return this._separatorPos[item.pos];
}
// TODO for bookmarks, check if it exists and find guid
// for everything else (folders, separators) look for parent/pred?
@ -717,6 +739,9 @@ BookmarksStore.prototype = {
case this._bms.TYPE_SEPARATOR:
record = new BookmarkSeparator();
// Create a positioning identifier for the separator
let parent = Svc.Bookmark.getFolderIdForItem(placeId);
record.pos = [placeId, parent].map(Svc.Bookmark.getItemIndex);
break;
case this._bms.TYPE_DYNAMIC_CONTAINER:

View File

@ -183,3 +183,5 @@ BookmarkSeparator.prototype = {
this.type = "separator";
}
};
Utils.deferGetSet(BookmarkSeparator, "cleartext", "pos");