Skip to content

Commit

Permalink
feat: use start/offset instead of bookmark
Browse files Browse the repository at this point in the history
  • Loading branch information
akdasa committed May 23, 2023
1 parent 3f964f0 commit dd6073e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
9 changes: 4 additions & 5 deletions lib/SyncService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,26 @@ export class SyncService<
const repResult: ReplicationResult = { aggregatesChecked: 0, aggregatesSynced: 0 }
const repOptions = { updateVersion: false, syncedAt: options.currentTime }

let lastBookmark: string|undefined = undefined
let lastSkip = 0
let continueFetching = true

while (continueFetching) {
// Get all entities that were synced after the last sync time
const findResult = await source.find(
syncedDuring(options.lastSyncTime, options.currentTime) as Query<TAggregate>,
{ bookmark: lastBookmark}
{ skip: lastSkip, limit: 25 }
)
const entitiesToSync = findResult.entities
lastBookmark = findResult.bookmark
// Stryker disable next-line all
continueFetching = findResult.entities.length > 0
lastSkip += findResult.slice.count

// Not Handled:
// server has entity with version 1 and syncedAt
// client has entity with version 1 but with no syncedAt
// after sync:
// client still has entity with no syncedAt

for (const sourceEntity of entitiesToSync) {
for (const sourceEntity of findResult.entities) {
repResult.aggregatesChecked++

let targetEntity: TAggregate|undefined = undefined
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@akdasa-studios/framework-sync",
"version": "0.2.4",
"version": "0.2.5",
"description": "Template",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down Expand Up @@ -33,7 +33,7 @@
},
"homepage": "https://github.com/akdasa-studios/framework-sync#readme",
"dependencies": {
"@akdasa-studios/framework": "0.5.1"
"@akdasa-studios/framework": "0.5.2"
},
"devDependencies": {
"@microsoft/api-extractor": "^7.34.4",
Expand Down

0 comments on commit dd6073e

Please sign in to comment.