question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Executing multiple queries does not save results of the previous query

See original GitHub issue

What is the current behavior? Executing multiple queries in the same firestoreConnect only preserves the result of the last one. Workaround is to use storeAs but there is a sideeffect. With storeAs, the results from populates are only saved for the very last query.

I could see in console the queries and populates are executed as expected but the result from the previous query becomes undefined when the result of the next query appears in the console.

Note that the commonality between my experience and #227 is that our queries were executed on the same collection.

What is the expected behavior?

  1. ideally, results of the query is preserved without storeAs
  2. results of populates is saved for all queries

Which version of redux-firestore are you using? What about other dependencies? 0.8.0 dependencies: immer “1.5.0” lodash “^4.17.11” reduce-reducers “0.4.3”

Which environments/browsers are affected by this issue? Did this work in previous versions or setups? reactjs web, react native in chrome and iphonex #227 mentions that popultes did work in 0.7.0

Minimal demo to reproduce issue (using codesandbox or similar)

const populates  = [{ child: 'activityID', root: 'activities', keyProp: 'key'}]

const mapStateToProps = state => {
  return {
    activities: state.firestore.ordered.act,
    currentActivities: populate(state.firestore, 'currentActivities', populates),
    completedActivities: populate(state.firestore, 'completedActivities', populates)
  }
}

export default compose(
  firestoreConnect(() => [
  {
    collection: 'activities', 
    storeAs: 'act'
  },
  {
    collection: 'users',
    doc: 'IF6HzQjcxjXmlwnDk5wBSYXnXh73', 
    subcollections: [{ collection: 'completedActivities' }],
    populates: populates,
    storeAs: 'completedActivities'
  },
   {
    collection: 'users',
    doc: 'IF6HzQjcxjXmlwnDk5wBSYXnXh73', 
    subcollections: [{ collection: 'currentActivities' }],
    populates: populates,
    storeAs: 'currentActivities'
  },
]),
connect(mapStateToProps)
)(ActScreen)


Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
prescottpruecommented, Nov 1, 2019

It does have a “principled way” - and there are even isLoaded and isEmpty helpers to assist in checking for those state as described in the queries section of the react-redux-firebase docs.

1reaction
namankumarcommented, Sep 4, 2019

Definitely. I think it’s fast becoming my go to lib for web/mobile dev now. It really simplifies the need for an ORM, writing your own redux-specific code, and the population capability is just genius 💯 The fact that I have the option of dropping in rn-firebase just makes forward planning so much easier

I’m learning now if the rrf has a principled way of deciding when to return data using store or when to query the database, though I suppose this might be out of scope for the lib. Any tips on how/where I could write code to make this decision would be great. Joining gitter now!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Save output of multiple queries into file? - sql server
Run your query and then right click on results and click save results to file. Once done rename the file from .rpt to...
Read more >
Why does my query run multiple times - Power Query
This article provides information about the various reasons that a Power Query query will sometimes run multiple times.
Read more >
Work with multi-statement queries | BigQuery - Google Cloud
The jobs.getQueryResults method returns the query results for the last statement to execute in the multi-statement query. If no statement was executed, no...
Read more >
5 Common Hibernate Mistakes That Cause Dozens of ...
JPA and Hibernate get often criticized for executing much more queries than expected. That's often caused by a few mistakes that you can...
Read more >
Executing multiple queries concurrently
Queries can access the data from a previous query through the @export directive, which injects the result of a field from a query,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found