-
Notifications
You must be signed in to change notification settings - Fork 107
feat: Snapshot reads #963
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
feat: Snapshot reads #963
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a couple small nits.
src/request.ts
Outdated
@@ -284,6 +285,16 @@ class DatastoreRequest { | |||
readConsistency: code, | |||
}; | |||
} | |||
if (options.readTime) { | |||
if (!reqOpts.readOptions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
I might make this explicitly, if (reqOpts.readOptions !== undefined)
.
Since JavaScript is so loose with its truthiness, I like to be explicit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to if (reqOpts.readOptions === undefined) {
reqOpts.readOptions = {}; | ||
} | ||
const readTime = options.readTime; | ||
const seconds = readTime / 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you just make this parseInt(readTime / 1000
, rather than having the floor? (I'm guessing this type should be an integer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseInt
only accepts string as a parameter. Are you sure about this? Should I convert it into a string and then use parseInt?
…-datastore into snapshot-reads # Conflicts: # test/request.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First follow-up
src/request.ts
Outdated
@@ -284,6 +285,16 @@ class DatastoreRequest { | |||
readConsistency: code, | |||
}; | |||
} | |||
if (options.readTime) { | |||
if (!reqOpts.readOptions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to if (reqOpts.readOptions === undefined) {
reqOpts.readOptions = {}; | ||
} | ||
const readTime = options.readTime; | ||
const seconds = readTime / 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parseInt
only accepts string as a parameter. Are you sure about this? Should I convert it into a string and then use parseInt?
system-test/datastore.ts
Outdated
@@ -308,6 +308,39 @@ describe('Datastore', () => { | |||
await datastore.delete(postKey); | |||
}); | |||
|
|||
// TODO: Modify this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be removed. Good catch!
}, | ||
}; | ||
const path = ['Post', 'post1']; | ||
const postKey = datastore.key(path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit - I would rename this to postKey1
or something similar to reference this is related to post1 rather than post2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same postKey
is used for both post1
and post2
. There is only one postKey
.
system-test/datastore.ts
Outdated
await sleep(1000); | ||
// Save new post2 data, but then verify the timestamp read has post1 data | ||
await datastore.save({key: postKey, data: post2}); | ||
const [entity] = await datastore.get(postKey, {readTime: savedTime}); // Include new options here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe it would be nice to do two of these; one for each post
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good plan.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
This implements the snapshot read feature which allows the user to get data from a previous point in time.