oc: improve modseqFromMessageChangeNumber to return an approximation.
Only for scenarios where we hadn't store the cn <-> modseq relationship
This commit is contained in:
parent
47be392d4f
commit
312084243b
|
@ -802,13 +802,43 @@ _compareFetchResultsByMODSEQ (id entry1, id entry2, void *data)
|
|||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (NSNumber *) modseqFromMessageChangeNumber: (NSString *) changeNum
|
||||
{
|
||||
NSDictionary *mapping;
|
||||
NSNumber *modseq;
|
||||
NSEnumerator *enumerator;
|
||||
id key;
|
||||
uint64_t found, target, current, replica_id, current_cn;
|
||||
NSString *closestChangeNum;
|
||||
|
||||
mapping = [[versionsMessage properties] objectForKey: @"VersionMapping"];
|
||||
modseq = [mapping objectForKey: changeNum];
|
||||
if (modseq) return modseq;
|
||||
|
||||
// Not found from stored change numbers for this folder.
|
||||
// Get the closest modseq for the change number given.
|
||||
// O(n) cost but will be unusual behaviour.
|
||||
target = exchange_globcnt([changeNum unsignedLongLongValue] >> 16);
|
||||
replica_id = [changeNum unsignedLongLongValue] & 0xFFFF;
|
||||
found = 0;
|
||||
enumerator = [mapping keyEnumerator];
|
||||
while ((key = [enumerator nextObject]))
|
||||
{
|
||||
current_cn = [(NSString *)key unsignedLongLongValue];
|
||||
if ((current_cn & 0xFFFF) != replica_id)
|
||||
continue;
|
||||
current = exchange_globcnt(current_cn >> 16);
|
||||
if (current < target && current > found)
|
||||
found = current;
|
||||
}
|
||||
|
||||
if (found)
|
||||
{
|
||||
closestChangeNum = [NSString stringWithUnsignedLongLong:
|
||||
(exchange_globcnt(found) << 16 | replica_id)];
|
||||
modseq = [mapping objectForKey: closestChangeNum];
|
||||
}
|
||||
|
||||
return modseq;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue