Hi everyone, I’m looking for a way to download less data from firebase.
I’m building an app that helps restaurant owners in managing their activities, an integrated system that shows the order taken by the waiter into the kitchen.
To give to the cookers a list of the orders that is always up to date I’m “refreshing” that list every 10 seconds, so if a new order comes in I’m able to show it to them.
I was wondering if there is another system to do it, right now I’m checking every 10 seconds the status of every single item of the order in every table ( see the image below) and this operation costs me a lot in terms of download. (just to give some numbers my whole DB is 25kb and I download 200MB every hour of test.
I was thinking about using the Listener Function but i saw that it can check onli a key per time and is not able to tell me in which node i had the change.
For example, let’s say that i put the listener on the node tavoli, if i change the status of item n6 of the order in table 1 straccetti will it be able to tell me where i had that change? Or it will just register a generic change ?
Setting the key to " / " will listen to your entire database. When any data is changed, the DataChanged block on the right can output which key changed and its new value.
200MB/hour seems like a lot of data, especially considering the size of your database. I don’t exactly know if a listener will create higher or lower data transfer amounts, but it seems like the most logical way of going about this.
If your database is updated for example, once a minute, calling a get function to the database every 10 seconds is extremely inefficient, whereas the listener would only pull data whenever there is data changed.
Thank you so much for the answer !
I have two questions:
if there is a change in the data that has to upload, for example, the orders of a specific table , the action triggered by data changed is performed also if I’am in another page of the app ( like for example the kitchen page ) ??
Does the listener "download data " while watching for changes? Because if it is the case i don’t know if it will solve my data consumption problem.
Thank you again !!!
is this in the live companion app or when you download the build that you experience such a large data consumption
I ask because the live companion will be receiving a lot of data.
When you attach a listener, the client sends the location (and potential query parameters) to the server. The server adds that listener to a list of all listeners of all connected clients. It then also sends back the initial data for that listeners.
Whenever a write operation is committed to the database, the server scans the listeners. For each relevant listener, the server sends an update to the client over the open web socket.
i.e. It is triggered by the write, thus a listener is basically saying I am here whenever you want to send me some data.
It’s when i use the live companion,
I’m having another problem, in my app i have to update a list every time a datum changes. (e.g if ths status of an item passes from 0 to 1 it has to be added)
The only way I found for doing that is that every time the listener register a change i send the user for a split second on another screen and send him back to the page where he was. ( it works in this way, but messes up the other screen change actions)
Is there a less “rude” solution to refresh the page ?
Thank you again
you should be able to update a list without ever leaving the page. can you show the blocks you ahve used to do this?
When the “Produzione” opens i call the listener, if a datum is changed, it opens a dedicated screen " Refresh Produzione" that has the only task to bring u back to Produzione when opened.
Before ding this i had in te " When Data Change" a call for the porocedure that writes the items in the list.