Skip to content
This repository has been archived by the owner on Aug 9, 2021. It is now read-only.

Feature/set multiple fields #409

Merged
merged 1 commit into from
May 7, 2019

Conversation

Schwartz10
Copy link
Contributor

Hello! A couple small things to note:

Copy link
Member

@oed oed left a 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.

  1. 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?
  2. Yeah, we've had some issues with the tests recently. It should be fixed if you rebase on develop!
  3. We would also need to add the setMultiple method to public and private of spaces. The spaces class is implemented a bit differently.
  4. 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 🙂

src/__tests__/privateStore.test.js Show resolved Hide resolved
src/publicStore.js Show resolved Hide resolved
@Schwartz10
Copy link
Contributor Author

@oed I'm struggling to get the privateStore tests to pass at the moment. It's odd because the part it's failing at is here. I've verified that it's not a race condition.

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 setMultiple for public and private spaces, is here (public) and here (private) ok?

@Schwartz10
Copy link
Contributor Author

@oed i fixed the tests. But do let me know about where to write the functionality for setMultiple for public and private spaces (see comment above for my best guess)

Copy link
Member

@oed oed left a 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)
Copy link
Member

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

src/keyValueStore.js Outdated Show resolved Hide resolved
@Schwartz10
Copy link
Contributor Author

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?

@oed
Copy link
Member

oed commented May 2, 2019

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 🙂

Copy link
Member

@oed oed left a 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 })
Copy link
Member

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?

Copy link
Contributor Author

@Schwartz10 Schwartz10 May 3, 2019

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?

Copy link
Contributor Author

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)
    })
  }

Copy link
Member

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!

Copy link
Member

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.

Copy link
Member

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
Copy link
Member

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?

Copy link
Contributor Author

@Schwartz10 Schwartz10 May 3, 2019

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?

Copy link
Member

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.

src/space.js Outdated Show resolved Hide resolved
@Schwartz10
Copy link
Contributor Author

Happy to rebase this, but want to wait just before we're ready to pull it in

Copy link
Member

@oed oed left a 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 })
Copy link
Member

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 })
Copy link
Member

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 })
Copy link
Member

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
Copy link
Member

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.

@Schwartz10
Copy link
Contributor Author

@oed all set! do you want me to squash this into 1 commit before I rebase?

@oed
Copy link
Member

oed commented May 6, 2019

Sweet @Schwartz10 and yes that would be nice!

@Schwartz10 Schwartz10 force-pushed the feature/set-multiple-fields branch from b1b2629 to 593b57b Compare May 6, 2019 16:28
@Schwartz10
Copy link
Contributor Author

@oed all set!

@oed oed added this to the Sprint 19 milestone May 7, 2019
@oed oed merged commit 837d633 into 3box:develop May 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants