Skip to content

Commit

Permalink
Fixes firestore replication of multiple document with the same server…
Browse files Browse the repository at this point in the history
…Timestamp (#6436)
  • Loading branch information
djoume committed Sep 24, 2024
1 parent 97f1c16 commit 5c6ec01
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/plugins/replication-firestore/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ export function replicateFirestore<RxDocType>(
);
sameTimeQuery = query(pullQuery,
where(serverTimestampField, '==', lastServerTimestamp),
where(primaryPath, '>', lastPulledCheckpoint.id),
orderBy(primaryPath, 'asc'),
where(documentId(), '>', lastPulledCheckpoint.id),
orderBy(documentId(), 'asc'),
limit(batchSize)
);
} else {
Expand Down
35 changes: 35 additions & 0 deletions test/replication-firestore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,5 +420,40 @@ describe('replication-firestore.test.ts', function () {

collection.database.destroy();
});
it('replicates all docs with identical serverTimestamp from the server', async () => {
const firestoreState = getFirestoreState();
const collection = await humansCollection.create(0);

const now = new Date();
const h1 = {
...makeFirestoreHumanDocument(
schemaObjects.humanData('replicated-1', 35, 'replicated')
),
serverTimestamp: now,
};
const h2 = {
...makeFirestoreHumanDocument(
schemaObjects.humanData('replicated-2', 27, 'replicated')
),
serverTimestamp: now,
};

await setDoc(DocRef(firestoreState.collection, 'replicated-1'), h1);
await setDoc(DocRef(firestoreState.collection, 'replicated-2'), h2);

await syncOnce(collection, firestoreState, {
pull: {
batchSize: 1,
},
push: {},
});

const allLocalDocs = await collection.find().exec();

assert.strictEqual(allLocalDocs.length, 2);

collection.database.destroy();
});

});
});

0 comments on commit 5c6ec01

Please sign in to comment.