Skip to content
Browse files

Support for BigCouch array-format sequence IDs

BigCouch is now using arrays as sequence IDs; TouchDB didn't format these properly.
Fixes #218.
  • Loading branch information...
1 parent 649d14f commit 496919466e92ce91ae7fcafb80038641f3b2e68b @snej snej committed Jan 15, 2013
Showing with 12 additions and 7 deletions.
  1. +7 −2 Source/ChangeTracker/TDChangeTracker.m
  2. +2 −2 Source/TDPuller.h
  3. +2 −2 Source/TDPuller.m
  4. +1 −1 Source/TDReplicator_Tests.m
View
9 Source/ChangeTracker/TDChangeTracker.m
@@ -78,8 +78,13 @@ - (NSString*) changesFeedPath {
kModeNames[_mode], _heartbeat*1000.0];
if (_includeConflicts)
[path appendString: @"&style=all_docs"];
- if (_lastSequenceID)
- [path appendFormat: @"&since=%@", TDEscapeURLParam([_lastSequenceID description])];
+ id seq = _lastSequenceID;
+ if (seq) {
+ // BigCouch is now using arrays as sequence IDs. These need to be sent back JSON-encoded.
+ if ([seq isKindOfClass: [NSArray class]] || [seq isKindOfClass: [NSDictionary class]])
+ seq = [TDJSON stringWithJSONObject: seq options: 0 error: nil];
+ [path appendFormat: @"&since=%@", TDEscapeURLParam([seq description])];
+ }
if (_limit > 0)
[path appendFormat: @"&limit=%u", _limit];
if (_filterName) {
View
4 Source/TDPuller.h
@@ -33,11 +33,11 @@
@interface TDPulledRevision : TD_Revision
{
@private
- NSString* _remoteSequenceID;
+ id _remoteSequenceID;
bool _conflicted;
}
-@property (copy) NSString* remoteSequenceID;
+@property (copy) id remoteSequenceID;
@property bool conflicted;
@end
View
4 Source/TDPuller.m
@@ -171,7 +171,7 @@ - (void) changeTrackerReceivedChanges: (NSArray*)changes {
for (NSDictionary* change in changes) {
@autoreleasepool {
// Process each change from the feed:
- NSString* remoteSequenceID = [change[@"seq"] description];
+ id remoteSequenceID = change[@"seq"];
NSString* docID = change[@"id"];
if (!docID || ![TD_Database isValidDocumentID: docID])
continue;
@@ -243,7 +243,7 @@ - (void) changeTrackerStopped:(TDChangeTracker *)tracker {
- (void) processInbox: (TD_RevisionList*)inbox {
// Ask the local database which of the revs are not known to it:
LogTo(SyncVerbose, @"%@: Looking up %@", self, inbox);
- NSString* lastInboxSequence = [inbox.allRevisions.lastObject remoteSequenceID];
+ id lastInboxSequence = [inbox.allRevisions.lastObject remoteSequenceID];
NSUInteger total = _changesTotal - inbox.count;
if (![_db findMissingRevisions: inbox]) {
Warn(@"%@ failed to look up local revs", self);
View
2 Source/TDReplicator_Tests.m
@@ -152,7 +152,7 @@ static void deleteRemoteDB(void) {
[db open];
id lastSeq = replic8(db, kRemoteDBURLStr, NO, nil);
- CAssertEqual(lastSeq, @"2");
+ CAssertEqual(lastSeq, @2);
CAssertEq(db.documentCount, 2u);
CAssertEq(db.lastSequence, 3);

0 comments on commit 4969194

Please sign in to comment.
Something went wrong with that request. Please try again.