Closed CodaFi closed 11 years ago
It certainly could be optimized. We could make folders act like NSString (vend the same folder as long as the paths are the same). I'll try to look into it.
I'd suggest using unified NSStrings using NSSet to refer to the folder and have an easy way to get a folder using a path.
What about an NSDictionary. Something like this: https://github.com/MailCore/mailcore2/compare/Folders-Cache#L1R38
I'm thinking it could be more thread safe if access to the dictionary was synchronized, which would make it safe for an MCOOperation to make one from a background thread.
It would leak folders in memory. It wouldn't work when you have several session to manage. It wouldn't work when the list of the folders would change.
NSString would be simpler to implement (event though NSString could leak too). To solve that you might have to implement a "Bag": NSSet with a counter for each element.
It looks hard enough to me to just not implement reference to the owning folder and leave the responsibility to the application to do that. The application can do that more easily.
The static qualifier does make memory management ambiguous, I'll give you that, but it would still work if the folders were to change, so long as you used the caching +folderWithPath:
variant. And I can foresee a problem if two accounts use the same folder path, but the folders have different flags. Yeah, you're right.
If we refer to the folder object, we might create a reference cycle or reference invalid folders.
If we use string, we might not have enough information to perform the request and/or there will be a performance hit if we have 100000 messages, we'll be keeping 100000 times the same string in memory. Though it can be optimized.
Let's try to work without it for now.