0

I have a database that store could potentially store LOTS of user individual data. I am working with Firebase and wondering how best to fetch my data.

For example, I have a machine, cog, gear, gizmo, screw, and bolt nodes in my database. One machine node has a relationship to several of these others.

machines: {
    abc: {
        cogUid: 123456789
        gearUid: 123456789
        gizmoUid: 123456789
        screws: {
            a: 123
            b: 456
            c: 789
        }
    }
    def: {
        ...
    }
    ghi: {
        ...
    }
}

When I fetch all of my machine nodes to display in a list, I also need to fetch all the related nodes using their uid's. For example, a list of machines, also shows next the machine the name of the cog and gizmo.

What is the most efficient way of retrieving all this data? If I fetch 500 machines and then need to do 5 more individual fetches per machine for their related data, that's a TON of fetches.

halfer
  • 19,824
  • 17
  • 99
  • 186
Josh Kahane
  • 16,765
  • 45
  • 140
  • 253
  • I Firebase it is often best to model your data to match the screens of your app. In that case you can easily only retrieve data that you intend to display and it is very unlikely you'll ever need to retrieve 2500 separate data items. – Frank van Puffelen Aug 01 '16 at 10:56
  • But in general fetches from Firebase are a lot faster than developers expect, because Firebase sends and pipelines them over a single connection. See http://stackoverflow.com/questions/35931526/speed-up-fetching-posts-for-my-social-network-app-by-using-query-instead-of-obse/35932786#35932786 – Frank van Puffelen Aug 01 '16 at 10:57
  • Ok thanks for the comment Frank. Less so than speed, would it not be a problem just making repeated requests to the server fast and in quick succession? I understand trying to match my model after the app screens, but I don't want to for example, repeat the data a gizmo 5 times in 5 different places. – Josh Kahane Aug 01 '16 at 11:24
  • 1
    Repeating data is very normal in NoSQL databases. But if you don't repeat data, you'll have to do repeated calls to get the data. Neither of them is likely a problem for a screenful of data. – Frank van Puffelen Aug 01 '16 at 13:33

0 Answers0