Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upResolve syncRecords #26
Conversation
| * Browser clients periodically request records, then finds matching browser | ||
| * objects and IPC calls this function to get resolved browser writes. | ||
| * @param {SyncRecord} record | ||
| * @param {Object=} existingObject (e.g. { location: "https://...", title: "cool", ... }) |
This comment has been minimized.
This comment has been minimized.
diracdeltas
Jan 1, 2017
Member
i would prefer the input to be the object that the browser has stored, which may have fields that are not in the SyncRecord. ex: a bookmark has a favicon that is not synced. this function should merge the SyncRecord against that object, leaving the non-synced fields untouched, and return the new object.
ex: browser sends
{
location: foo
favicon: bar
objectId: baz
}
sync record is of the form:
{
location: abc
objectId: baz
}
the returned merged object is:
{
location: abc
objectId: baz
favicon: bar
}
| * objects and IPC calls this function to get resolved browser writes. | ||
| * @param {SyncRecord} record | ||
| * @param {Object=} existingObject (e.g. { location: "https://...", title: "cool", ... }) | ||
| * @returns {SyncRecord} resolved record which the browser should do |
This comment has been minimized.
This comment has been minimized.
diracdeltas
Jan 1, 2017
Member
along the lines above: i think this should return an object of the same form as existingObject (plus extra fields from SyncRecord if any), not a SyncRecord.
This comment has been minimized.
This comment has been minimized.
ayumi
Jan 3, 2017
•
Author
Contributor
I think that makes sense when the browser provides an existing object.
Without an existingObject, for example a Create record, Sync would still need to send the SyncRecord to the browser for the browser to create its object.
Do we want resolve() to return multiple "types": browser object w/ merged SyncRecord, original SyncRecord or null?
| if (existingObject) { | ||
| return nullIgnore() | ||
| } else { | ||
| return record |
This comment has been minimized.
This comment has been minimized.
diracdeltas
Jan 1, 2017
Member
i feel like this should return the merge of record and existingObject
| } | ||
| case proto.actions.UPDATE: | ||
| if (existingObject) { | ||
| return record |
This comment has been minimized.
This comment has been minimized.
| lastAccessedTime: site.lastAccessedTime || Date.now(), | ||
| creationTime: site.creationTime || Date.now() | ||
| } | ||
| return record.$type.create(Object.assign( |
This comment has been minimized.
This comment has been minimized.
diracdeltas
Jan 1, 2017
Member
i think this should return just a regular JS object instead of a proto message since the browser doesn't currently do any proto parsing
This comment has been minimized.
This comment has been minimized.
ayumi
Jan 3, 2017
Author
Contributor
to confirm: a protobuf object is created here but not encoded into bytes, so if it's sent to the browser via IPC will it be able to access the object?
| if (!record || record.action !== proto.actions.UPDATE) { | ||
| throw new Error('Missing UPDATE syncRecord.') | ||
| } | ||
| switch (record.objectData) { |
This comment has been minimized.
This comment has been minimized.
diracdeltas
Jan 1, 2017
Member
seems ok for these all to just return record.objectData + record.objectId
e926865
to
1ffac21
Try to resolve syncRecord Update to Create when needed
|
@diracdeltas i've made changes to do resolution of syncRecords + existingObjects. could you take another look? |
| * browser must update its local values with the new sync records, performing | ||
| * conflict-resolution as necessary. | ||
| * browser should find objects with matching objectIds then call | ||
| * RESOLVE_SYNC_RECORDS to perform conflict resolution. | ||
| */ | ||
| RECEIVE_SYNC_RECORDS: _, /* @param {string} categoryName, @param {Array.<Object>} records */ |
This comment has been minimized.
This comment has been minimized.
diracdeltas
Jan 5, 2017
Member
i wonder if categoryName is needed any more; browser can infer category from the record fields?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ayumi
Jan 5, 2017
•
Author
Contributor
sync's requestUtil still needs to make separate s3 ListObject requests per category.
so if the user syncs a subset of the available categories it would be faster and we'll also avoid sending browser clients unwanted data.
This comment has been minimized.
This comment has been minimized.
diracdeltas
Jan 5, 2017
Member
i see, that means RESOLVE_SYNC_RECORDS and RESOLVED_SYNC_RECORDS will only ever send records in the same category, right? so it seems those should both send a categoryName parameter
This comment has been minimized.
This comment has been minimized.
ayumi
Jan 5, 2017
Author
Contributor
correct, those two calls would only call with same-category records.
browser clients can examine each record's objectData to determine what to do with them.
This comment has been minimized.
This comment has been minimized.
diracdeltas
Jan 5, 2017
Member
up to you but i think it is slightly neater to send categoryName explicitly because all records will be in the same category
| @@ -8,7 +8,7 @@ | |||
| "flow": "flow; test $? -eq 0 -o $? -eq 2", | |||
| "build": "yarn upgrade && browserify client/sync.js | uglifyjs - > bundles/bundle.js", | |||
| "browsertest": "yarn start-test; browserify test/client/*.js test/*.js | uglifyjs - | tape-run; yarn stop-test", | |||
| "browsertest-client": "yarn start-test; browserify test/client/*.js | uglifyjs - | tape-run --browser chrome; yarn stop-test", | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ayumi
Jan 5, 2017
Author
Contributor
yes; browsertest-client is helpful for developing client-only code because it runs faster. it's only used in dev, so it's ok to skip uglify as long as you check browsertest before committing.
| * webview -> browser | ||
| * browser must update its local values with the resolved sync records. | ||
| */ | ||
| RESOLVED_SYNC_RECORDS: _, /* @param {Array.<Object>} records */ |
This comment has been minimized.
This comment has been minimized.
diracdeltas
Jan 5, 2017
Member
given that this doesn't have a categoryName parameter, it seems the browser has to infer category from the record object anyway, so categoryName probably isn't needed for RECEIVE_SYNC_RECORDS either
ayumi commentedJan 1, 2017
•
edited
No description provided.