I'm working on a website for collecting unpaid invoices. A visitor is able to place an order (provide his/her company data and upload one or more unpaid invoices) and pay for the service BEFORE making a user account.
This means that I have to add the uid
afterward. Normally this isn't a big deal but I'm duplicating the invoice and company data to a file node.
Because of that, firebase has to loop through all the invoices nodes to check where the uid is matching the current user id when a user wants to fetch their own invoices.
invoices
invoice 1
general
uid: 'uid-123'
orderid: 'order-1234'
documents
creditor
...
invoice 2
general
uid: 'uid-123'
orderid: 'order-1234'
documents
creditor
...
invoice 3
general
uid: 'uid-543'
orderid: 'order-3434'
documents
creditor
...
Is this approach/structure ok (I don't want a huge bill in a few months because firebase has to loop through 100 - 1000 - 5000 invoice nodes every time) or is there a way around to become the following structure which seems better/faster.
invoices
uid 1
invoice 2
invoice 4
invoice 5
uid 2
invoice 1
invoice 3
invoice 8