Changeset 18

Show
Ignore:
Timestamp:
10/05/08 12:57:50 (16 years ago)
Author:
jon
Message:

Re-implemented caching in a less stupid way. Still want to get it intercepting content updates before I declare #2 closed, though. Also did some modest refactoring.

Location:
Trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • Trunk/ABSortByLogSizePlugin.m

    r16 r18  
    4646- (NSString *)pluginVersion 
    4747{ 
    48         return @"1.0"; 
     48        return @"1.1"; 
    4949} 
    5050 
  • Trunk/AILogSizeSort.h

    r16 r18  
    2727@interface AILogSizeSort : AISortController 
    2828{ 
     29        NSMutableDictionary *logSizeCache; 
    2930} 
    3031 
    31 +(unsigned long long)getContactLogSize:(AIListContact *)listObject; 
     32-(unsigned long long)getCachedLogSize:(AIListContact *)listContact; 
     33+(unsigned long long)getContactLogSize:(AIListContact *)listContact; 
    3234 
    3335@end 
  • Trunk/AILogSizeSort.m

    r16 r18  
    3232#import <Adium/AIMetaContact.h> 
    3333 
     34#import <Adium/ESDebugAILog.h> 
     35 
    3436@implementation AILogSizeSort 
    3537 
     
    4143- (void)didBecomeActiveFirstTime 
    4244{ 
     45        AILog(@"Sort by log size controller became active for first time."); 
     46        logSizeCache = [[NSMutableDictionary alloc] init]; 
     47        AILog(@"%@", logSizeCache); 
    4348} 
    4449 
     
    105110 
    106111/*! 
    107  * Allow users to manually sort groups. 
     112 * @brief Allow users to manually sort groups 
    108113 */ 
    109114-(BOOL)canSortManually 
     
    112117} 
    113118 
    114 /** 
     119-(unsigned long long)getCachedLogSize:(AIListContact *)listContact 
     120{ 
     121        AILogWithSignature(@"Getting cached log size for %@/%@.", [[listContact account] explicitFormattedUID], [listContact UID]); 
     122         
     123        if([logSizeCache valueForKey:[[listContact account] explicitFormattedUID]] == nil) 
     124        { 
     125                [logSizeCache setValue:[[NSMutableDictionary alloc] init] forKey:[[listContact account] explicitFormattedUID]]; 
     126        } 
     127         
     128        NSMutableDictionary *accountDictionary = [logSizeCache valueForKey:[[listContact account] explicitFormattedUID]]; 
     129         
     130        if([accountDictionary valueForKey:[listContact UID]] == nil) 
     131        { 
     132                AILogWithSignature(@"\tNo cache hit."); 
     133                [accountDictionary setValue:[NSNumber numberWithUnsignedLongLong:[AILogSizeSort getContactLogSize:listContact]] forKey: [listContact UID]]; 
     134        } 
     135         
     136        AILogWithSignature(@"\tLog file size: %@", [accountDictionary valueForKey:[listContact UID]]); 
     137        return [[accountDictionary valueForKey:[listContact UID]] unsignedLongLongValue]; 
     138} 
     139 
     140/*! 
     141 * @brief Returns the total aggregate log size for a contact 
     142 * 
    115143 * Returns the total aggregate log size for a contact.  For meta-contacts, the 
    116144 * total log file size of all sub-contacts is returned.  If no log exists or if 
    117145 * something else goes wrong, 0 is returned. 
    118146 * 
    119  * @param listObject an AIListContact for which to retrieve a total log file size 
     147 * @param listContact an AIListContact for which to retrieve a total log file size 
    120148 * @return the total log file size in bytes or 0 if an error occurred 
    121149 */ 
    122 +(unsigned long long)getContactLogSize:(AIListContact *)listObject 
     150+(unsigned long long)getContactLogSize:(AIListContact *)listContact 
    123151{ 
    124152        NSFileManager *fileManager = [NSFileManager defaultManager]; 
    125153         
    126         if([listObject isMemberOfClass:[AIMetaContact class]]) 
     154        if([listContact isMemberOfClass:[AIMetaContact class]]) 
    127155        { 
    128156                // Recurse through all sub-contacts 
    129                  
    130157                id contact; 
    131158                unsigned long long size = 0; 
    132159                 
    133                 NSEnumerator *contactEnumerator = [[listObject listContacts] objectEnumerator]; 
     160                NSEnumerator *contactEnumerator = [[(AIMetaContact *)listContact listContacts] objectEnumerator]; 
    134161 
    135162                while(contact = [contactEnumerator nextObject]) 
     
    143170        { 
    144171                // Find the path to the directory containing the log files for this contact 
    145                 NSString *path = [[AILoggerPlugin logBasePath] stringByAppendingPathComponent:[AILoggerPlugin relativePathForLogWithObject:[listObject UID] onAccount: [listObject account]]]; 
     172                NSString *path = [[AILoggerPlugin logBasePath] stringByAppendingPathComponent:[AILoggerPlugin relativePathForLogWithObject:[listContact UID] onAccount: [listContact account]]]; 
    146173                 
    147174                // Grab an enumerator for all log files for this contact 
     
    171198#pragma mark Sorting 
    172199/*! 
    173  * @brief Alphabetical sort 
     200 * @brief Sort by log size 
    174201 */ 
    175202int logSizeSort(id objectA, id objectB, BOOL groups) 
     
    188215        } 
    189216         
    190         unsigned long long sizeA = [AILogSizeSort getContactLogSize:objectA]; 
    191         unsigned long long sizeB = [AILogSizeSort getContactLogSize:objectB]; 
    192          
     217        // Get a reference to one and only AILogSizeSort instance.  If this sorting method is being 
     218        // called, it should always be the case that AILogSizeSort is the active sort controller. 
     219        AISortController *sortController = [[adium contactController] activeSortController]; 
     220         
     221        unsigned long long sizeA = 0; 
     222        unsigned long long sizeB = 0; 
     223         
     224        if([sortController isMemberOfClass:[AILogSizeSort class]]) 
     225        { 
     226                sizeA = [(AILogSizeSort *)sortController getCachedLogSize:objectA]; 
     227                sizeB = [(AILogSizeSort *)sortController getCachedLogSize:objectB]; 
     228        } 
     229        else 
     230        { 
     231                sizeA = [AILogSizeSort getContactLogSize:objectA]; 
     232                sizeB = [AILogSizeSort getContactLogSize:objectB]; 
     233        } 
     234 
    193235        if(sizeB == sizeA) 
    194236        { 
  • Trunk/Info.plist

    r2 r18  
    33<plist version="1.0"> 
    44<dict> 
     5        <key>AIMinimumAdiumVersionRequirement</key> 
     6        <string>1.3</string> 
    57        <key>CFBundleDevelopmentRegion</key> 
    68        <string>English</string> 
     
    1012        <string></string> 
    1113        <key>CFBundleIdentifier</key> 
    12         <string>com.yourcompany.${PRODUCT_NAME:identifier}</string> 
     14        <string>com.eatthepath.${PRODUCT_NAME:identifier}</string> 
    1315        <key>CFBundleInfoDictionaryVersion</key> 
    1416        <string>6.0</string> 
     
    2022        <string>AdIM</string> 
    2123        <key>CFBundleVersion</key> 
    22         <string>1.0</string> 
     24        <string>1.1</string> 
    2325        <key>NSPrincipalClass</key> 
    2426        <string>ABSortByLogSizePlugin</string> 
    25         <key>AIMinimumAdiumVersionRequirement</key> 
    26         <string>1.3</string> 
    2727</dict> 
    2828</plist>