Rock U - Data - Persisted Datasets
Transcribed Video Content
On the Internet, performance is super important. And in Rock, you've probably set up some complex queries that may cause some complexity or some slowness. Now persistent datasets are something where you can basically say, here you go, Rock. Here's my query. Run it for me on a scheduled basis and output the results for me.
This will really speed up some processes for you. So let's look at how to set up persistent datasets in Rock right now. Let's add a new persistent dataset. So we'll go down to admin tools, up to settings, then we'll start typing in persisted. We see persisted datasets pop up right here.
So I've clicked on it and we actually already have a few set up. This is a really nice grid. So if you have a ton of different persisted datasets, you can filter, sort and search through them easily. You can also manually refresh them if you have that enabled and you can quickly preview the results. So you can add one here, but let's look into a persistent dataset we've set up already.
This one is called campus. We've also picked an access key of campus. And this is important because you'll use this with your lava to be able to get the results of this persisted dataset later. You can also pick whether this is active, meaning we could if you set this to false, you would have the persisted dataset Lava filter return null for this dataset, so it wouldn't be available through Lava. It's also really important for persistent datasets to describe what this is used for so that people don't have to read through your scripts to understand what information is being displayed.
But here is an example of a script. And this is a helpful example because it's simply using Lava to go through a list of the campuses we have and it's taking some of the information from those campuses such as ID and name, then what's really important here is that we're outputting that information to JSON. Now JSON is the structure of data that we use with persisted datasets and you'll wanna make sure that whatever query you're using is outputting its results as JSON. You'll see what it looks in just a moment. But yeah, this is a really simple command and it's probably more simple than you would need something persisted datasets for.
Usually a big heavy query or script is something that you'll want to use a persisted dataset for. Otherwise, you might just put something this in an HTML block and let it run. But persisted datasets are really nice for those large datasets that you either want to cache or persist on a specific schedule. So we've picked to enable all lava commands here. You can be specific with what you wanna enable for the purpose of security.
Then here is the actual schedule that we want this to run on. So if we click this, we can pick between an interval. We have a handy slider where we can pick the minutes, hours, or days, how often we want this dataset to be updated or we can pick a schedule either a named one or a unique one where we're simply making a really specific judgment about when does this schedule start, what's the duration, is it recurring, things that. But let's just say we want this to refresh every twelve hours. Then we can pick once someone loads up this dataset, how long after it's loaded do we want to cache this dataset in our memory and every time you open it, this interval will restart.
Then we can also pick when we want this dataset to expire. If applicable, say at some point this dataset is no longer relevant and we know when that date is, then you can pick when this expires and if someone uses Lava to try to access this dataset, it won't be there anymore. Then entity type. This can be helpful if you're gonna take the results of this persisted dataset and run it through a filter such as append following, and that is a lot of filter that requires entity type to be defined so that it has all the information it needs. So unless you have a use case where you need to express what the entity type this relates to, for example, in this case, this would be campuses, You don't need to fill in the entity type.
Then we can also pick whether we want to allow manual refresh, which I showed earlier, but we'll save this and manual refresh is right here. Let's just do this as an example. It took very little time to build and the result size is negligible, but you can see when this dataset was last refreshed. You can also click here to preview the results, which is super nice. And this is what JSON looks .
We can see exactly the ID and name of the campus that we wanted to output. Now we're looking at a page where I actually have the persisted dataset using Lava set up. So let's look at this HTML block. We've simply used this filter where we're assigning data to equal campus, and that was the access key we set up earlier. And we're filtering and we have persisted dataset here.
So that means data that we're accessing is directly from the persisted dataset and we can use these objects essentially that we set up within the persisted dataset and output information. So we're outputting the campus ID is item dot ID, campus is item dot name. We save and here's the output. Now you've got some data refreshing on a regular schedule. You've been able to hand off some complexity over to Rock.
Now remember, if you ever have a heavy query that doesn't need to be in real time, you should create a persistent dataset. They can be really helpful for things that. Thanks for watching this video and have a great day.