-
Notifications
You must be signed in to change notification settings - Fork 65
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.
Thanks @Schwartz10, this is super cool!
1 - 2 are to your questions, 3 - 4 are additional thoughts.
- I don't have a strong opinion on what the function should return. What do you mean by "the full update profile"? All entries in the store or just all entries that you added?
- Yeah, we've had some issues with the tests recently. It should be fixed if you rebase on develop!
- We would also need to add the
setMultiple
method to public and private of spaces. The spaces class is implemented a bit differently. - Kind of feel like the function should live in the
KeyValueStore
class with minimal wrappers in private and public store. This should be similar with spaces.
See also additional inline comments 🙂
@oed I'm struggling to get the Wondering if there is something else I have to adjust in the mocks? Could you provide a second pair of eyes on this one? With respect to the |
@oed i fixed the tests. But do let me know about where to write the functionality for |
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.
Looks great now 🙌
Yep that's exactly the place for setMultiple in spaces :)
Just a small nitpick below 👇
async setMultiple (keys, values) { | ||
utils.throwIfNotEqualLenArrays(keys, values) | ||
const dbKeys = keys.map(this._genDbKey, this) | ||
const encryptedValues = values.map(this._encryptEntry, 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.
Cool, didn't know you could pass this
like that. I've always just used .bind
Hey @oed ! Everything seems to be working well. Tests are passing, and running all these methods for both public/private spaces and public/private profile stores in a real application is working too. How should i proceed? |
Awesome @Schwartz10 I'll have another look at it first thing tomorrow. I assume it should be good, then It'll get merged to develop. Can probably make another release tomorrow as well, if it's urgent 🙂 |
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.
Looks good, just a few questions before I merge. Maybe you'd want to rebase on develop? Isn't strictly needed though :)
this._requireLoad() | ||
this._ensureConnected() | ||
const timeStamp = new Date().getTime() | ||
return this._db.put(nextKey, { value: values[index], timeStamp }) |
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.
Why not call this.set
instead? Am I missing something?
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.
Weird! thought I left a comment about this.
For some reason running the private store, calling this.set
from within setMultiple
did not save any database entries. It passes in the tests but does not work in my actual application. As far as i could tell, it didn't have to do with race conditions, the this
context, or anything else I investigated. I was (and still am) super confused, especially because it worked fine for the public store. This commit solved the problem. Do you have any idea why that would be the case?
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.
I just verified this again in my actual application - returning this.set
from within setMultiple
causes private fields to return null
. SO weird. Would love to know why this is happening.
returning this._db.put
from inside this.set
doesn't solve it.
And old-school promisifying this.set
doesn't do it either:
set (key, value) {
return new Promise(async (resolve, reject) => {
throwIfUndefined(key, 'key')
this._requireLoad()
this._ensureConnected()
const timeStamp = new Date().getTime()
await this._db.put(key, { value, timeStamp })
resolve(true)
})
}
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.
So this is only an issue with the privateStore and not the publicStore? That is indeed very strange!
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.
Oh, I think it's because this
in that context might be the subclass and not the superclass! I.e. it uses privateStore set
which tries to encrypt the entry again. Then when you get the entry it tries to decrypt it once, when it's encrypted two times.
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.
So yes, we should definitely not call this.set
then. I think that's better though. We can move this._requireLoad()
and this._ensureConnected()
to be called only once in setMultiple
😃
src/space.js
Outdated
throwIfUndefined(nextKey, 'key') | ||
return store.set(PREFIX + nextKey, values[index]) | ||
}, Promise.resolve()) | ||
return true |
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.
Why not do keys = keys.map(e => PREFIX + e)
then call store.setMultiple
?
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.
Made this change. Also, just realizing, what happens if key is a number? Is it converted to a string somewhere?
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.
👍 Here it will be converted to a string since we +
with a string. However it's a good question if a number is passed into orbitdb as a key. I'm not completely sure about that.
Happy to rebase this, but want to wait just before we're ready to pull it in |
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.
Yup, makes sense! And thanks for clarifying the this.set
issue! Just one small change then we should be good to go!
this._requireLoad() | ||
this._ensureConnected() | ||
const timeStamp = new Date().getTime() | ||
return this._db.put(nextKey, { value: values[index], timeStamp }) |
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.
So this is only an issue with the privateStore and not the publicStore? That is indeed very strange!
this._requireLoad() | ||
this._ensureConnected() | ||
const timeStamp = new Date().getTime() | ||
return this._db.put(nextKey, { value: values[index], timeStamp }) |
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.
Oh, I think it's because this
in that context might be the subclass and not the superclass! I.e. it uses privateStore set
which tries to encrypt the entry again. Then when you get the entry it tries to decrypt it once, when it's encrypted two times.
this._requireLoad() | ||
this._ensureConnected() | ||
const timeStamp = new Date().getTime() | ||
return this._db.put(nextKey, { value: values[index], timeStamp }) |
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.
So yes, we should definitely not call this.set
then. I think that's better though. We can move this._requireLoad()
and this._ensureConnected()
to be called only once in setMultiple
😃
src/space.js
Outdated
throwIfUndefined(nextKey, 'key') | ||
return store.set(PREFIX + nextKey, values[index]) | ||
}, Promise.resolve()) | ||
return true |
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.
👍 Here it will be converted to a string since we +
with a string. However it's a good question if a number is passed into orbitdb as a key. I'm not completely sure about that.
@oed all set! do you want me to squash this into 1 commit before I rebase? |
Sweet @Schwartz10 and yes that would be nice! |
b1b2629
to
593b57b
Compare
@oed all set! |
Hello! A couple small things to note:
setMultiple
? I noticed the tests seem to returntrue
ifset
completes without errors? We could do a similar thing forsetMultiple
, but it also might be nice to return the full, updated profile. https://github.com/3box/3box-js/compare/develop...openworklabs:feature/set-multiple-fields?expand=1#diff-efe243c83b3a509aaca8757b8cc08d35R32