What I’m trying to do:
I have a number of large data tables, with one entry per user.
Whenever I want to find a value for a user from a data table, I have to first find the row corresponding to that user. I end up doing this a lot and it significantly affects performance, so I would like to know how to do it best.
What I’ve tried and what’s not working:
Currently, each time I want a data value for a user, I search for a unique property of the user in the data table to find that user’s row e.g.:
rowForUser = app_tables.user_data.get(email_address=email_address)
dataValue = rowForUser['data_column']
I know I can keep hold of that row while I’m in the same function, but in practice I need to get data all over the code base, so I end up often repeating that search to find rowForUser
.
It occurred to me before that I could add a column to the main Users data table which contained links to each user’s row in the user_data data table. And add additional columns with links to all the other relevant data tables.
However, it turns out that when you put a row link into a data table, whenever you load a row in that data table, it also loads the whole linked row. So, if I put links to all the user’s data table rows in as columns in the Users table, a simple call to anvil.users.get_user()
would load all data for that user (which would probably fail as a result of needing too much memory, and certainly seems inefficient).
This must be a completely standard problem, so surely I’m missing something obvious. Thoughts and help greatly appreciated!