How to disable serializable state invariant middleware - redux

export const store = configureStore({
reducer: {
[userAuthApi.reducerPath]: userAuthApi.reducer,
cart:cartSlice.reducer
},
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware().concat(userAuthApi.middleware)
})
The Above is My store configuration
I am getting error saying serializable state invariant middleware took too long if your state or actions very large disable the middleware, i don't have a large state at all, Actions means which actions it's talking about , i am getting this error a after adding one more api to my end points of rtk query , how many endpoints are too many.
My development Mode is slowed down to very very low , causing me so much problem while building what's causing this , what's the solution

Related

I'm getting error like this - Cloud Firestore 'Oops, collections failed to load!' [duplicate]

I'm building a small chat app with expo, connected to Firestore. Here is the code to fetch the chat data:
useEffect(() => {
console.log("Loading snapShots on firebase");
const unsubscribe = db.collection('chats').onSnapshot(snapshot => (
setChats(snapshot.docs.map(doc => ({
id: doc.id,
data: doc.data()
})))
))
setTimeout(()=>{
unsubscribe();
}, 1000);
}, [])
This code is normally if I followed correctly documentation, supposed to close the snapShot listener after one second. If it does, I still get a [FirebaseError: Quota exceeded.] message and my app is very small, the data too.
Firebase quotas are reset daily at midnight (Pacific time). According to your timezone, it may differ. If you're located in Europe, it actually may be in the middle of the day. So if you reach the daily limitation, there is nothing you can do, but wait until the "next" day. Or you can update to the Spark Plan.
But remember, once you got the quota exceeded message your project will not be accessible until the quotas are reset.
As also #Dharmaraj mentioned in his comment, you might also consider using a get() call, and not listen for real-time changes. In this way, you attach a listener that is discounted automatically once you got the data.
Please also remember to not keeping your Firebase console open, as it is considered another Firestore client that reads data. So you'll be also billed for the reads that are coming from the console.

If I implement onSnapshot real-time listener to Firestore in Cloud Function will it cost more?

I have a listener to Firestore DB changes and it fetches automatically every time there is a change, however, if I decide to implement it in Cloud Function and call it from the client app, will it cost more because it will running 24h/7 even when users are not using the app?
This is in Client side:
firestore()
.collection('Collection').doc().collection('public')
.where('act', '==', 1)
.orderBy('time', 'asc')
.limit(10)
.onSnapshot({
error: (e) => this.setState({ errorMessage: e, loading: false }),
next: (querySnapshot) => { this._calculateLocationDistance(querySnapshot) },
});
Moreover, is it necessary to do it in Cloud Function? Is it risky if I leave it in the client side?
You can't really use listeners effectively in Cloud Functions. Cloud Functions are meant to be stateless. They serve a single request at a time, and clean up afterward. If you try to use a listener, it just won't work the way you expect. Cloud Functions also don't keep a socket open to the requester. Once a response is sent, the connection is closed, and there's no way to keep it open.
Given these constraints, functions typically just use get() to fetch data a single time, and return the results to the client. If you want realtime results, that should be implemented on the client.
If you are working with a backend that can keep a socket connection open to a client, it is no less expensive to have a listener on the backend that delivers results to the client. You are still charged a document read for each document read by the listener as it continues to receive results.

Firestore Deadline Exceeded Node

I would like to load collection that is ~30k records. I.e load it via.
const db = admin.firestore();
let documentsArray: Array<{}> = [];
db.collection(collection)
.get()
.then(snap => {
snap.forEach(doc => {
documentsArray.push(doc);
});
})
.catch(err => console.log(err));
This will always throw Deadline Exceeded error. I have searched for some sorts of mechanism that will allow me to paginate trough it but I find it unbelievable not to be able to query for not that big amount in one go.
I was thinking that it may be that due to my rather slow machine I was hitting the limit but then I deployed simple express app that would do the fetching to app engine and still had no luck.
Alternatively I could also export the collection with gcloud beta firestore export but it does not provide JSON data.
I'm not sure about firestore, but on datastore i was never able to fetch that much data in one shot, I'd always have fetch pages of about 1000 records at a time and build it up in memory before processing it. You said:
I have searched for some sorts of mechanism that will allow me to paginate trough
Perhaps you missed this page
https://cloud.google.com/firestore/docs/query-data/query-cursors
In the end the issue was that machine that was processing the 30k records from the Firestore was not powerful enough to get the data needed in time. Solved by using, GCE with n1-standard-4 GCE.

Remote Config implemented at rnfirebase have a mandatory subscription?

Initially I implemented the exactly Remote Config example from that link:
https://rnfirebase.io/docs/v3.3.x/config/example
firebase.config().fetch()
.then(() => {
return firebase.config().activateFetched();
})
.then((activated) => {
if (!activated) console.log('Fetched data not activated');
return firebase.config().getValue('hasExperimentalFeature');
})
.then((snapshot) => {
const hasExperimentalFeature = snapshot.val();
if(hasExperimentalFeature) {
enableSuperCoolFeature();
}
// continue booting app
})
.catch(console.error);
My idea is not subscribe the Remote Config. I just would like to know if it have any changes at APP startup (componentWillMount).
But I see that using that code above the Remote Config variables are not updating at a new APP startup. I searched and found that info about 12 hours cache:
Remote Config caches values locally after the first successful fetch
request. By default the cache expires after 12 hours, but you can
change the cache expiration for a specific request by passing the
desired cache expiration, in seconds, to
fetchWithExpirationDuration:completionHandler: (on iOS) or fetch (on
Android).
They also NOT recommend to change that cache to a small value:
Note that if you reduce this expiration time to a very small value,
you might start hitting the client-side throttling limit, which
prevents your client from making a fetch request more than a few times
per hour.
https://firebase.google.com/support/faq/#remote-config-requests
BUT, as I have to update values at APP startup, I decided to not follow this recommendation and test. In my tests using firebase.config().fetch(0)(fetch 0 to avoid cache) the APP apparentely is not subscribing the Remote Config. There are no listeners at javascript side.
So, could I continue using firebase.config().fetch(0) without worry? The update only occurs when code runs?
How is the internal implementation of firebase.config().fetch() / snapshot?
Using cache timeout of 0 seconds is only meant for development purposes. This will not work for you in production.
As per the documentation, you can fetch 5 times in a 60 minute window - before getting throttled by the client SDK.
Does that work for you?

Where to sync redux store and firebase?

I recently started learning react and redux and am confused as how to sync the data? I'm using create-react-app and redux-thunk.
Suppose I'm making a todolist. So should I add a task into redux and update the entire store to firebase using store.subscribe in index.js?
Or should I update the firebase store and then update the redux store? I think this would be the better method as the application would move only in response to the firebase store. But this approach slows the application re-render as the data change has to wait for the async request to finish which isn't good on a slow internet connection. And would make the user experience slow.
Like this.
export const startAddTaskAction = (task) => {
return (dispatch, getState) => {
database.ref('tasks').push(task)
.then(() => {
dispatch(addTaskAction(task));
});
};
};
Or do I update both simultaneously in the redux store and in firebase in the dispatch? But then what if the users internet connection fails? Firebase won't be able to write to itself but redux would show the task as saved?
Like this:
export const startAddTaskAction = (task) => {
return (dispatch, getState) => {
database.ref('tasks').push(task);
dispatch(addTaskAction(task));
};
};
Which way should I do this and why is it better then the others?
Go with First one you should wait until you push the data into firebase that is the best practice to do.
Let me explain the cases why you should do in this way
What if there is no connection at all user able to add all tasks but at the end when he reload the page he will be surprised that there is no data at all.
For all crud we use _id which is generated by databases if you don't hit the server you don't even get data at all.
Rather than giving unpredictable results to users it's better to let him wait put some time interval to api if it exceeds show some message net connection is slow

Resources