coalesce bookmark notifications and suppress all notifications during loading

bookmarks, increases startup speed (bug 236373)
This commit is contained in:
pinkerton%aol.net 2004-06-01 21:58:50 +00:00
Родитель de83598bda
Коммит ddd78e27eb
5 изменённых файлов: 60 добавлений и 1 удалений

Просмотреть файл

@ -506,6 +506,9 @@ static void doHTTPUpdateCallBack(CFReadStreamRef stream, CFStreamEventType type,
-(BOOL) readNativeDictionary:(NSDictionary *)aDict
{
//gather the redundant update notifications
[self setAccumulateUpdateNotifications:YES];
[self setTitle:[aDict objectForKey:BMTitleKey]];
[self setDescription:[aDict objectForKey:BMDescKey]];
[self setKeyword:[aDict objectForKey:BMKeywordKey]];
@ -513,14 +516,23 @@ static void doHTTPUpdateCallBack(CFReadStreamRef stream, CFStreamEventType type,
[self setLastVisit:[aDict objectForKey:BMLastVisitKey]];
[self setNumberOfVisits:[[aDict objectForKey:BMNumberVisitsKey] unsignedIntValue]];
[self setStatus:[[aDict objectForKey:BMStatusKey] unsignedIntValue]];
//fire an update notification
[self setAccumulateUpdateNotifications:NO];
return YES;
}
-(BOOL) readSafariDictionary:(NSDictionary *)aDict
{
//gather the redundant update notifications
[self setAccumulateUpdateNotifications:YES];
NSDictionary *uriDict = [aDict objectForKey:SafariURIDictKey];
[self setTitle:[uriDict objectForKey:SafariBookmarkTitleKey]];
[self setUrl:[aDict objectForKey:SafariURLStringKey]];
//fire an update notification
[self setAccumulateUpdateNotifications:NO];
return YES;
}
@ -535,10 +547,14 @@ static void doHTTPUpdateCallBack(CFReadStreamRef stream, CFStreamEventType type,
elementInfoPtr = (CFXMLElementInfo *)CFXMLNodeGetInfoPtr(myNode);
if (elementInfoPtr) {
NSDictionary* attribDict = (NSDictionary*)elementInfoPtr->attributes;
//gather the redundant update notifications
[self setAccumulateUpdateNotifications:YES];
[self setTitle:[[attribDict objectForKey:CaminoNameKey] stringByRemovingAmpEscapes]];
[self setKeyword:[[attribDict objectForKey:CaminoKeywordKey] stringByRemovingAmpEscapes]];
[self setDescription:[[attribDict objectForKey:CaminoDescKey] stringByRemovingAmpEscapes]];
[self setUrl:[[attribDict objectForKey:CaminoURLKey] stringByRemovingAmpEscapes]];
//fire an update notification
[self setAccumulateUpdateNotifications:NO];
} else {
NSLog(@"Bookmark:readCaminoXML - elementInfoPtr null, load failed");
return NO;

Просмотреть файл

@ -760,6 +760,8 @@ NSString* BookmarkFolderDockMenuChangeNotificaton = @"bf_dmc";
-(void) itemAddedNote:(BookmarkItem *)theItem atIndex:(unsigned)anIndex
{
if (![BookmarkItem allowNotifications]) return;
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:theItem,BookmarkFolderChildKey,
[NSNumber numberWithUnsignedInt:anIndex],BookmarkFolderChildIndexKey,nil];
@ -769,6 +771,8 @@ NSString* BookmarkFolderDockMenuChangeNotificaton = @"bf_dmc";
-(void) itemRemovedNote:(BookmarkItem *)theItem
{
if (![BookmarkItem allowNotifications]) return;
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSDictionary *dict = [NSDictionary dictionaryWithObject:theItem forKey:BookmarkFolderChildKey];
NSNotification *note = [NSNotification notificationWithName:BookmarkFolderDeletionNotification object:self userInfo:dict];

Просмотреть файл

@ -50,6 +50,7 @@
NSString* mKeyword;
NSString* mUUID;
NSImage* mIcon;
BOOL mAccumulateItemChangeUpdates;
}
// Setters/Getters
@ -71,6 +72,9 @@
-(BOOL) isChildOfItem:(BookmarkItem *)anItem;
// Notificaiton of Change
+(void) setSuppressAllUpdateNotifications:(BOOL)suppressUpdates;
+(BOOL) allowNotifications;
-(void) setAccumulateUpdateNotifications:(BOOL)suppressUpdates;
-(void) itemUpdatedNote; //right now, just on title & icon - for BookmarkButton & BookmarkMenu notes
// Methods called on startup for both bookmark & folder

Просмотреть файл

@ -84,6 +84,9 @@ NSString *CaminoTrueKey = @"true";
@implementation BookmarkItem
static BOOL gSuppressAllUpdates = NO;
//Initialization
-(id) init
{
@ -96,7 +99,8 @@ NSString *CaminoTrueKey = @"true";
mUUID = nil;
// if we set the icon here, we will get a memory leak. so don't.
// subclass will provide icon.
mIcon = NULL;
mIcon = NULL;
mAccumulateItemChangeUpdates = NO;
}
return self;
}
@ -221,13 +225,39 @@ NSString *CaminoTrueKey = @"true";
[aIcon retain];
[mIcon release];
mIcon = aIcon;
if (![BookmarkItem allowNotifications]) return;
NSNotification *note = [NSNotification notificationWithName:BookmarkIconChangedNotification
object:self userInfo:nil];
[[NSNotificationCenter defaultCenter] postNotification:note];
}
// Prevents all NSNotification posting from any BookmarkItem.
// Useful for suppressing all the pointless notifications during load.
+(void) setSuppressAllUpdateNotifications:(BOOL)suppressUpdates
{
gSuppressAllUpdates = suppressUpdates;
}
+(BOOL) allowNotifications
{
return !gSuppressAllUpdates;
}
// Helps prevent spamming from itemUpdatedNote:
// calling with YES will prevent itemUpdatedNote from doing anything
// and calling with NO will restore itemUpdatedNote and then call it.
-(void) setAccumulateUpdateNotifications:(BOOL)accumulateUpdates
{
mAccumulateItemChangeUpdates = accumulateUpdates;
if (!mAccumulateItemChangeUpdates)
[self itemUpdatedNote]; //fire an update to cover the updates that weren't sent
}
-(void) itemUpdatedNote
{
if (gSuppressAllUpdates || mAccumulateItemChangeUpdates) return;
NSNotification *note = [NSNotification notificationWithName:BookmarkItemChangedNotification object:self userInfo:nil];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc postNotification:note];

Просмотреть файл

@ -123,6 +123,10 @@ static unsigned gFirstUserCollection = 0;
[root setTitle:NSLocalizedString(@"BookmarksRootName", @"")];
[self setRootBookmarks:root];
[root release];
// Turn off the posting of update notifications while reading in bookmarks.
// All interested parties haven't been init'd yet, and/or will recieve the
// managerStartedNotification when setup is actually complete.
[BookmarkItem setSuppressAllUpdateNotifications:YES];
if (![self readBookmarks]) {
// one of two things happened. we are importing off an old xml file
// for startup, OR we totally muffed reading the bookmarks. we'll hope
@ -150,6 +154,7 @@ static unsigned gFirstUserCollection = 0;
[aFolder setTitle:NSLocalizedString(@"Bookmark Toolbar",@"Bookmark Toolbar")];
}
}
[BookmarkItem setSuppressAllUpdateNotifications:NO];
// setup special folders
[self setupSmartCollections];
mSmartFolderManager = [[KindaSmartFolderManager alloc] initWithBookmarkManager:self];