Database Read/Write INCREDIBLY SLOW

Just got an idea… But I’ll have to test it.

What if I could convert a list of things into JSON, then save it as a single record in the database? I would have to convert it back into a list of things to populate a repeating group.

I’ve encountered this similar use case as yours and this is what I did.
Instead of having the questions and answers as objects (Things) I simply made them as two lists of texts.

So I have a Thing called Template and it has two fields which are lists of texts, Questions and Answers. So if you have 10 questions you will first create these as a list of text and save it to Questions field of your Template thing. Then for the Answers you will create a list of 10 empty strings, “”,"",""… (you get the idea). Creating an empty strings list in bubble is a bit tricky but I don’t want to deviate so won’t explain it for now but it’s easy to do.

So now we have our Template table with only a single row which has our Questions (list of texts) and answers (list of empty texts).

Then on your User you also have a Questions field and Answers all list of texts as in thr Template.

So when a user signs up or (when they start a questionnaire in your case), you simply set the User’s Questions field to Template’s Questions:first (remember you have only a single row in Template).
You do the same for Answers.

For displaying them you can use the Answers as the data source for your repeating group. Then for the Questions you will get the current cell index and use it to get the corresponding question in the Questions list. The reason for using the Answers as the data source for the repeating group and not the Questions is that it will make it easy for us to save all the answers together or even save anytime a question is answered.
Note that we will always be saving the entire list.

This makes things really fast as you’re only dealing with a single row and two fields. So there is no object creation. You’re only accessing and modifying a field.
I have this used in a production app and so far I haven’t had any complaints. My list of questions was shorter (20) but everything looks instant. I expect your 48 questions to also be almost instant.

If you get stuck implementing this idea hit me up.

That will work and it’s very similar to my idea above. Only difference is that instead of storing a single json string and having to do the conversions I simply use a list of texts so I don’t have to do any conversions.

Hi @seanhoots, thanks for taking the time to help. It seems to be a good solution.

However, just get a little more specific, every of my questions have 3 inputs (1x slider and 2x checkboxes). So that would mean that the Template thing would have 4 fields (Question, Answer-Slider, Answer-Check1, Answer-Check2) right? And the ways to find the right answers for a question is by their position in the list.

Now, every user will complete the survey several times since these are profiles about employees in their company. If I get it right, a user thing would have a field that would be a list of surveys, and a survey thing would be the same thing as a template thing…

I hope I’m clear…

Maybe, without providing full steps, you could just point me how you create empty list of text? With CSV? or using :plus item/:minus item?

So that would mean that the Template thing would have 4 fields (Question, Answer-Slider, Answer-Check1, Answer-Check2) right?

Yes if you have more than one answer then you’re going to need the same number of fields.

And the ways to find the right answers for a question is by their position in the list.

Yes.

This will all depend on whether the questions in each survey are the same or not. So in my solution i mentioned that you will copy each of the template questions to the user. That is not really needed. It’s just that in my use case it was more of a list of favourite things and answers (e.g. My favorite city - Paris, My favorite color - Red, etc). And the User could add their own questions and answers as well as delete the template questions. That is why each user had their own copy of the questions.

If in your case each survey is always going to have the same list of questions then you don’t even need to save the questions on the user, only the responses.

This is how I will structure your case.

Template
  Questions - text list
  Answer-Slider - number list
  Answer-Check1 - yes/no list
  Answer-Check2 - yes/no list

Survey(Employee)
  Name - text
  Answer-Slider - number list
  Answer-Check1 - yes/no list
  Answer-Check2 - yes/no list
  My Employer - User(Employer)

User(Employer)
  Surveys(Employees) - Survey(Employee) list

I’m not sure if for your use case you will need empty list of text. I think you will need empty list of numbers and empty list of yes/no which is actually very easy to do.

There is nothing like an empty number or empty yes/no. So for numbers the default will be 0 and for yes/no you could choose no.
So you can simply use the :plus item to add a 0 or no to the corresponding answer field anytime a new question is added.

But assuming you need empty text that one is a bit tricky as i mentioned. This is because when you use the :plus item bubble will expect you to enter some text. If you leave it black bubble will see it as an error.
So instead what i do is use the List expression element from the Toolbox plugin to generate the empty list like below

The important thing here is to leave the Item expression box empty and the Result type to be text.
For the datasource i’m passing it the list of template questions.
So basically this will create an empty string list having the same length as the number of questions.
Then in a workflow you will just set the value of the ListItemExpression to your answer field like below:

You could actually use the same technique to create a default list (not empty) list for numbers and yes/no.

But this is not needed as you can simply use the :plus item to add 0 one at a time anytime a new question is added.

Assuming you wanted to do same for yes/no field, the important thing is the the Item expression should be a false (this is javascript) and not a “no” (bubble). Bubble knows how to change false to no and true to yes.

Thank you for taking all that time. I spent the last hours to see the best way I can implement your solution in my app. A challenge is that the 48 questions don’t show all at once; they are separated into 7 categories. In this process I don’t want to mix up the position of the answers and questions.

Still have one question: Once I populated a repeating group with the selected questions and answer field, how do you save it? You mentioned that you had to overwrite the hole list every time, but what’s your process?

Hi @neerja, I just upgraded to the Professionnal plan. I tried the +5 units boost. I saw a little improvement but still way too slow for what the task is…

After a lot research and tries, I got to find a workaround that fits my need. My surveys are now super snappy; no delay when saving/deleting/editing!

Instead of having a record for each of the 48 questions, I now have only one containing all the data in JSON. So theres a workflow to transform the JSON into data that can be put in a repeating group, and another workflow to retrieve the data from the repeating group and make a JSON string with it.

1 Like

Hi there,

And how did you do this JSON save and JSON convert?

Thanks!

Hey @ryanck, I’m working on writing a post on the solution. It will be published in the “tip” category of the forum. I will put a link here in this post when it’s online.

2 Likes

Thanks! I´ll keep an eye on this post.

Hey @ryanck, I just posted a demonstration of my solution. There are explanations and a link to a demo app. Everything that is important has been commented, so feel free to explore it!

2 Likes

Hello @julienallard1, wow amazing post.

I wanted to reply earlier but I haven´t been able to see the full post.

Really nice work what you did.

Thanks a lot for the explanation and the in depth review of all the things you´ve tested to get this working.

Have a nice day.

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.