Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Support for BigCouch array-format sequence IDs
Browse files Browse the repository at this point in the history
BigCouch is now using arrays as sequence IDs; TouchDB didn't format these properly.
Fixes #218.
  • Loading branch information
snej committed Jan 15, 2013
1 parent 649d14f commit 4969194
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
9 changes: 7 additions & 2 deletions Source/ChangeTracker/TDChangeTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions Source/TDPuller.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions Source/TDPuller.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Source/TDReplicator_Tests.m
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4969194

Please sign in to comment.