Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve syncRecords #26

Merged
merged 2 commits into from Jan 5, 2017
Merged

Resolve syncRecords #26

merged 2 commits into from Jan 5, 2017

Conversation

@ayumi
Copy link
Contributor

ayumi commented Jan 1, 2017

No description provided.

* 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.

Copy link
@diracdeltas

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.

Copy link
@diracdeltas

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.

Copy link
@ayumi

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.

Copy link
@diracdeltas

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.

Copy link
@diracdeltas

diracdeltas Jan 1, 2017

Member

same as above

lastAccessedTime: site.lastAccessedTime || Date.now(),
creationTime: site.creationTime || Date.now()
}
return record.$type.create(Object.assign(

This comment has been minimized.

Copy link
@diracdeltas

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.

Copy link
@ayumi

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.

Copy link
@diracdeltas

diracdeltas Jan 1, 2017

Member

seems ok for these all to just return record.objectData + record.objectId

@ayumi ayumi force-pushed the feature/resolution branch 4 times, most recently from e926865 to 1ffac21 Jan 4, 2017
Try to resolve syncRecord Update to Create when needed
@ayumi ayumi changed the title WIP syncRecord resolution syncRecord resolution Jan 5, 2017
@ayumi ayumi changed the title syncRecord resolution resolve syncRecords Jan 5, 2017
@ayumi ayumi force-pushed the feature/resolution branch from 1ffac21 to be7ae31 Jan 5, 2017
@ayumi ayumi changed the title resolve syncRecords Resolve syncRecords Jan 5, 2017
@ayumi
Copy link
Contributor Author

ayumi commented Jan 5, 2017

@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.

Copy link
@diracdeltas

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.

Copy link
@diracdeltas

diracdeltas Jan 5, 2017

Member

also this should be renamed to something like GET_EXISTING_RECORDS

This comment has been minimized.

Copy link
@ayumi

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.

Copy link
@diracdeltas

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.

Copy link
@ayumi

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.

Copy link
@diracdeltas

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.

Copy link
@diracdeltas

diracdeltas Jan 5, 2017

Member

was this change intentional?

This comment has been minimized.

Copy link
@ayumi

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.

Copy link
@diracdeltas

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 ayumi force-pushed the feature/resolution branch from be7ae31 to 016bef4 Jan 5, 2017
@ayumi ayumi merged commit 9b9e901 into staging Jan 5, 2017
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@ayumi ayumi deleted the feature/resolution branch Jan 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.