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

LocalDatastore fixes for React-Native #753

Merged
merged 18 commits into from
Mar 26, 2019

Conversation

dplewis
Copy link
Member

@dplewis dplewis commented Mar 20, 2019

Closes: #747

Adds a new Prefix on stored object keys. This prevents retrieving and clearing unnecessary objects in the redux data store.

  • Batches remove requests whenever possible
  • Batches get requests whenever possible
  • Improve Docs
  • Improve Typings
  • Clean up tests by removing hardcoded keys
  • Add more tests
  • Create Utils to remove dependency cycles
  • Throws error if LDS is not enabled

@codecov
Copy link

codecov bot commented Mar 20, 2019

Codecov Report

Merging #753 into master will increase coverage by 0.12%.
The diff coverage is 99.45%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #753      +/-   ##
==========================================
+ Coverage   90.25%   90.38%   +0.12%     
==========================================
  Files          54       55       +1     
  Lines        4640     4709      +69     
  Branches     1077     1084       +7     
==========================================
+ Hits         4188     4256      +68     
- Misses        452      453       +1
Impacted Files Coverage Δ
src/LocalDatastoreUtils.js 100% <100%> (ø)
src/StorageController.react-native.js 100% <100%> (ø) ⬆️
src/ParseObject.js 89.89% <100%> (+0.02%) ⬆️
src/LocalDatastoreController.default.js 100% <100%> (ø) ⬆️
src/LocalDatastoreController.browser.js 100% <100%> (ø) ⬆️
src/ParseQuery.js 96.36% <100%> (ø) ⬆️
src/LocalDatastoreController.react-native.js 100% <100%> (ø) ⬆️
src/LocalDatastore.js 98.55% <98.3%> (-0.43%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 089e208...6c96156. Read the comment docs.

@dplewis dplewis requested a review from acinader March 20, 2019 15:06
Copy link
Contributor

@acinader acinader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some questions.....

src/LocalDatastore.js Outdated Show resolved Hide resolved
src/LocalDatastore.js Show resolved Hide resolved
src/LocalDatastore.js Outdated Show resolved Hide resolved
src/LocalDatastore.js Outdated Show resolved Hide resolved
src/LocalDatastoreController.default.js Outdated Show resolved Hide resolved
src/ParseObject.js Outdated Show resolved Hide resolved
src/ParseObject.js Outdated Show resolved Hide resolved
src/ParseObject.js Outdated Show resolved Hide resolved
src/ParseObject.js Outdated Show resolved Hide resolved
src/StorageController.react-native.js Outdated Show resolved Hide resolved
@dplewis dplewis requested a review from acinader March 20, 2019 22:03
src/LocalDatastore.js Outdated Show resolved Hide resolved
Copy link
Contributor

@acinader acinader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some questions and comments. i think going over the types in comments and flow types in function declarations with a fine tooth comb is in order.

src/LocalDatastore.js Outdated Show resolved Hide resolved
src/LocalDatastore.js Outdated Show resolved Hide resolved
src/LocalDatastore.js Show resolved Hide resolved
src/LocalDatastoreController.browser.js Outdated Show resolved Hide resolved
src/LocalDatastoreController.react-native.js Outdated Show resolved Hide resolved
src/ParseObject.js Outdated Show resolved Hide resolved
src/ParseObject.js Show resolved Hide resolved
src/ParseQuery.js Show resolved Hide resolved
src/ParseQuery.js Show resolved Hide resolved
dplewis added a commit that referenced this pull request Mar 21, 2019
Closes: #687, #670, #723, #669

* Pin packages
* (Jest) Fix deprecated setupTestFrameworkScriptFile
* (Codecov) Fix coverage folders
* Update Parse.Cloud.define docs
* Add discource badge to Readme

Pending #753
@acinader
Copy link
Contributor

@dplewis lmk or assign to me when ready for review.

@dplewis dplewis mentioned this pull request Mar 21, 2019
@dplewis
Copy link
Member Author

dplewis commented Mar 21, 2019

Its ready for review

@acinader
Copy link
Contributor

looking, but you'll need to rebase.

@acinader
Copy link
Contributor

let's see if i can just push the button to update.

Copy link
Contributor

@acinader acinader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found one error which requires a fix which I point out in the comment.

I think that the rest of my comments you can take or leave.

Working this with you has been good. Hope it isn't too painful :).

src/.flowconfig Outdated Show resolved Hide resolved
src/LocalDatastore.js Show resolved Hide resolved
src/LocalDatastoreController.browser.js Outdated Show resolved Hide resolved
src/LocalDatastoreController.browser.js Outdated Show resolved Hide resolved
src/LocalDatastoreController.default.js Outdated Show resolved Hide resolved
src/LocalDatastoreController.react-native.js Outdated Show resolved Hide resolved
src/LocalDatastoreController.react-native.js Show resolved Hide resolved
src/LocalDatastoreController.react-native.js Outdated Show resolved Hide resolved
src/ParseObject.js Outdated Show resolved Hide resolved
src/StorageController.react-native.js Outdated Show resolved Hide resolved
@dplewis dplewis requested a review from acinader March 21, 2019 23:25
@dplewis
Copy link
Member Author

dplewis commented Mar 21, 2019

Working this with you has been good. Hope it isn't too painful :).

We should do this again sometime :)

Copy link
Contributor

@acinader acinader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an actual question. and a suggestion or two to take or leave.

i'm going to have to find a use parse in the client now, cause I wanna use this!

const fromPinPromise = this.fromPinWithName(pinName);
const [pinned] = await Promise.all([fromPinPromise, toPinPromises]);
const toPin = [...new Set([...(pinned || []), ...objectKeys])];
return this.pinWithName(pinName, toPin);
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take 2 at using reduce here, this time with your code. Untested as I'm not setup to test. Just for fun,

async _handlePinAllWithName(name: string, objects: Array<ParseObject>): Promise {
  const pinName = this.getPinName(name);
  const toPinPromises = objects.reduce((accumulator, parent) => {
    const toPin = this._getChildren(parent); // get an object with the children by key
    const parentKey = this.getKeyForObject(parent);
    toPin[parentKey] = parent._toFullJSON(); // add the parent
    const promises = Object.keys(toPin).map(objectKey => 
      this.pinWithName(objectKey, [toPin[objectKey]])) // pin 'em.
        .then(() => objectKey) // return the object key when the promise is done
    );
    return accumulator.concat(promises);
  }, []);

  const fromPinPromise = this.fromPinWithName(pinName);
  const [fromPins, toPins] = await Promise.all([fromPinPromise, toPinPromises]);
  const allToPin = [...new Set([...(fromPins || []), ...toPins])];
  return this.pinWithName(pinName, allToPin);
},

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that but for some reason to get the toPins I would have to call Promise.all twice

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd have to be able to step through this with a debugger to see.

One thing I'm curious about is why this.pinWithName(objectKey, [toPin[objectKey]]))

I'm assuming that toPin[objectKey] is already an array, so not sure why it needs to be put in an array.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getChildren returns key -> object and not key -> [object]

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having another pair of eyes debugging this is really helpful

src/LocalDatastoreController.browser.js Outdated Show resolved Hide resolved
const keys = await RNStorage.getAllKeys();
const storage = {};
const results = await RNStorage.multiGet(keys);
results.map((pair) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use forEach here instead of map cause you're not capturing the returned array.

map returns an array with one element per element in the original array
forEach return nothing.

so forEach is more memory efficient if you're not returning something.

map composes very nicely with filter.

src/LocalDatastoreController.react-native.js Outdated Show resolved Hide resolved
Copy link
Contributor

@acinader acinader left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@dplewis dplewis merged commit b6bc90c into parse-community:master Mar 26, 2019
@dplewis dplewis deleted the lds-react-native branch March 26, 2019 16:17
dplewis added a commit that referenced this pull request Mar 26, 2019
* ⚡️ Release v2.3.0

Closes: #687, #670, #723, #669

* Pin packages
* (Jest) Fix deprecated setupTestFrameworkScriptFile
* (Codecov) Fix coverage folders
* Update Parse.Cloud.define docs
* Add discource badge to Readme

Pending #753

* add user subclass fix

* add typescript to readme

* typo

* add discourse to js sdk

* remove url module #758 (review)

* Update CHANGELOG.md
@adoucoure
Copy link

@dplewis I just want to say thank you and the whole Parse contributors for your efforts!
Really appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JSON.parse() error on Object.destroy()
3 participants