currently, in a page i have a section to show a chart from quickchart, and the data on the chart is meant to show data points from a google sheet. below are all of the blocks used:
the problem is that the process is extremely slow (5+ minutes). the label’s text is able to display “start”, but the code hangs for a while afterwards. i do understand this is not the best way to go about this, which is why i’m asking what could be a better way to optimize these blocks. even though it’s not the best option, google sheets is the best one for me at the moment, as i don’t really have a lot of time to switch to using another database
One reason your code is so slow is that accessing stored variables is a slow process. And you have them in loops so any delay is going to be multiplied.
Here’s how to avoid that: when using a stored variable, only reference it when you need to change its value. Otherwise, just use app variables. So you can assign your stored variable(s) to app variable(s) and use the app variables throughout your code. When needing to change a stored variable, set its value and then immediately assign the app variable to that value as well.
with some external help, i was able to update the function and other blocks like so, along with inserting a pivot table from the original spreadsheet to reduce the amount of rows the app reads:
it loads a little quicker than normal, but now a new issue arises, and it’s loading into a different class (which is the same class screen, but displays different data). when trying to access another class after going back to the home screen, the code seems to hang for a while.
to detail the class loading issue, say i load into class 1 (er64Hz) from the home screen after logging in, and everything loads fine including the specific quickchart data. however, if i go back to the home screen, and try to load into class 2 (fg45Wg), the code just hangs and it’s stuck on the loading screen. there may be an issue with trying to load class 2’s specific data, but i’m not sure what it is.
@wulfy_starr Just an FYI, we strongly suggest not adding in any special characters or spaces when naming variables, components, and functions. This will likely cause some unexpected issues or crashes when it is time to compile the code for downloading or publishing. They must only contain alphanumeric characters and underscores (e.g. get “very bad’s” should be getVeryBads or get_very_bads.
i know this is somewhat completely different to what i was already talking about, but i decided to start working on a different data graph, and these are the blocks so far:
i have added a debugging timer to see how long the process will take to just add one dataset (out of 5) to the quickchart image, but it’s been going for longer than 18 minutes… which leads me to think this does not work at all, or it’s just taking INCREDIBLY long. i think it’s the latter, as i tested each function individually and the label does return them in under 10 seconds… is there a mistake in the code somewhere? this does concern me as i am planning to add 4 more datasets in the chart link (as this is a stacked bar chart)
It would be hard for me to help decipher all that. For one, the screenshot resolution is low so it’s actually hard to see the blocks. But beyond that, it just seems like too many functions to me.
Your functions are nested several layers deep and include loops. It’s best to avoid all that if you can.
Something that might help you make more efficient code is the first occurrence of block. This block finds where an item is in a list. So instead of looping through the list of values and checking each one until you find a match, you can replace that whole function with a single block.
really sorry about that… the monitor i’m using is kind of low resolution, so i try to zoom in as much as i can for the screenshots.
however, after researching how to use the “first occurrence of” block, i was able to find a much cleaner solution! now the graph loads in under 10 seconds with the data it pulls so far. thank you very much :]
(edit: i’ve learned that it can load even faster without the function, so i removed that)
hmm… the chart doesn’t load anymore if i try to add a second dataset to the url. the “badsStats” variables do return a value when i set a label’s text to one of them, however :\
(edit: i added a debugging label to see where the process gets stuck, and it seems to never progress past setting the variables. the “veryBadsStats” variables set just fine, however)
the student name does need to be stored to the device; and either way, i am satisfied with the current speed. my main concern was just trying to load separate quickchart datasets now
I think you misunderstood or perhaps didn’t read the post I linked to earlier about stored variables. But it sounds like you’re good with how that’s working.
I doubt it. You’ll have to do some more debugging. I would separate the set app variable... lines with debugging labels so you know which list of values block is causing the code to stop working.
It’s not a great idea to have unnamed columns so I’d fix that too. I don’t know if that’s causing the problem or not.
i have used this debugging process, and the code appears to get stuck at “set 5”, and doesn’t go to “set all”, even though there is data in that specific column
the data the variables are pulling from is from a google sheets pivot table, so i unfortunately can’t rename the unnamed columns, even if i wanted to :\