How to get all the information from Firebase and store it locally in TinyDB?

342 views
Skip to first unread message

Sergey

unread,
Aug 2, 2017, 7:05:44 AM8/2/17
to MIT App Inventor Forum
Hi, i'm working on a dictionary with database stored in Firebase. Firebase works fine, but i want the app to be usefull offline. So i guess i need to get all the information from firebase and store it in TinyDB on the device. I'm planning to do it with "Download database" button.
I tried this, but it didn't work. I guess the mistake is in "for each item in list block". Please, help :)

firefox_2017-08-02_13-50-33.png

Sergey

unread,
Aug 2, 2017, 2:03:31 PM8/2/17
to MIT App Inventor Forum
Well, i tried it on a smaller database(3000 entries instead of 10000) and it works fine. So, i guess big database caused the app to hang. Is there any limit to the size of the database that TinyDB can handle? Or is there another way to store dictionary data on the device? Any advice will be helpfull.

Abraham Getzler

unread,
Aug 2, 2017, 2:43:12 PM8/2/17
to MIT App Inventor Forum
You could pre-load your file as a .txt file in the Media Drawer,
and load it into TinyDB from //yourfile.txt on first run.

Also see the Files section of this FAQ:

ABG

Sergey

unread,
Aug 2, 2017, 5:20:43 PM8/2/17
to MIT App Inventor Forum
Thank you for you reply, Abraham! Well, i can upload my database file to App Inventor, but i don't see the way to import it in TinyDB like i do it with Firedase. I have attached the small portion of my database. Would you, please, take a look at it and tell if i can use it as local database somehow. My whole file has nearly 10000 entries in it. Oh, and it's in russian, by the way.
a-test.json

Taifun

unread,
Aug 2, 2017, 6:17:41 PM8/2/17
to MIT App Inventor Forum

Abraham Getzler

unread,
Aug 2, 2017, 8:57:52 PM8/2/17
to MIT App Inventor Forum
Your 10,000 entries might give you trouble.

You can parse JSON text into a list of pairs using the Web component's Web1.JSONTextDecode block.
From there, a lookup in pairs block should get you your lookup value.

Here's a project I did for some one looking to make a big language translate app ...


That project suffered from a long loading time.

You might need to break up your file into 26+ files by their first letter, and
just load that subset as needed.

ABG

gerrikoio

unread,
Aug 3, 2017, 11:34:20 AM8/3/17
to MIT App Inventor Forum
This is very much a resourcing challenge based on how much data can you hold in memory at any one time and how much data can you store on the phone. So have you calculated your storage requirements for the 10,000 records? If there is sufficient storage space, then it is a case of working out the optimum number of values you should have per tag, as each time you call a tag your app will attempt to store all of the values in memory at once. Thus you may need to redesign the structure of your firebase table in order for it to be downloaded into tinydb due to these memory constraints. This is the same approach Abraham took when splitting his file into 26 files.

Then you need to relook at how you download the data in each tag as you cannot use the "for each" option as you have shown, due to the asymmetric callback "GotValue" method. For each tag in the TagList you should wait until the GotValue has triggered and you have processed the data before moving onto the next tag in your TagList.
Reply all
Reply to author
Forward
0 new messages