I am trying to use a calculated model in Google App Maker to store data from an external API. I am able to load the data to a model and render it in a table. But now I want to filter the data in the table without calling the external API again.
For example if I use the Weather (Call REST services) sample code, after the weather is rendered on screen I want to click a button to only show the days with the temperature is below 32F. How would I do that without calling the external APIs again to reload the model.
After talking out loud, I believe I can answered my own question. I hope this helps others and please correct me if I am wrong.
What I am asking isn't possible with Calculated Models. How a Calculated Model works is the server script (query script) calls the external database, receives the data and formats (cleans up) the data following a Datasource. The datasource cleans up the data to fit within the Model before returning the data as Records to the
Client. Once the data is on the Client everything on the serve is forgotten.
So to search the data 2 options I can think of:
Create different Datasources, Models or Parameters that calls the external database every time and returning the filtered data to the Client.
Or use the javascript filter() method on the records already loaded to client and some extra code and ui to show the filtered results. The filter() method doesn't modify the records on the client but the results can shown on another table.
Related
For example: I have 10 pages. And for 8 of them, I need to have the same data. So in the getStaticProps method I doing API calls. But they are the same! I don't want to do the same calls 8 times to get the same data. I want to do one call and have access to this data from anywhere.
Are we have some solutions for this?
You can share data across all pages in build time by implementing a simple file system cache, when you get data from your api you can saving it in a file with specific name as key , for next time you can first check if there is a file with that key and get the data from it.
I am exploring using ADX as a timeseries data store for sensor metrics. Our current solution is storing data in MSSQL and I'm testing ADX as an alternative. I was able to set up data ingestion and I can perform basic queries, and with the added aggregation functions, computing insights and statistics seems to be much faster.
As part of the solution, we have a API data access layer used by clients and our web portal to query data for display and analysis use. I am currently transforming the MSSQL queries to the KQL version and I'm hitting a stumble block on data pagination.
We have a function to query historical data using a combination of:
an start/end date,
a device identifier,
and some paging options
records per page,
current page,
column sorting / additional filtering
Currently this is handled in a SQL SP on the back-end, by getting the total number of records and pages (which is set as output on the API so that the front-end can use this data in the table view), then getting the records based on the input parameters and pagination details to return a record set - quite straight forward.
Any suggestions on how to achieve effective pagination using ADX/KQL?
I found a section in the docs on pagination on stored query results, but as the queries are dynamic based on user input, so this does not sound like a viable option.
When you paginate (for example viewing result 21-30) you need to consider if you are taking a snapshot of the result and paging through it or viewing live data. If you expect new rows coming in to not affect your pagination, than stored query results is that snapshot. Once you generate it you can select specific rows from it based on your page calculation.
Most examples of Flux use a todo or chat example. In all those examples, the data set you are storing is somewhat small and and be kept locally so not exactly sure if my planned use of stores falls in line with the flux "way".
The way I intend to use stores are somewhat like ORM repositories. A way to access data in multiple ways and persist data to the data service, whatever that might be.
Lets say I am building a project management system. I would probably have methods like these for data retrieval:
getIssueById
getIssuesByProject
getIssuesByAssignedUser
getIssueComments
getIssueCommentById
etc...
I would also have methods like this for persisting data to the data service:
addIssue
updateIssue
removeIssue
addIssueComment
etc...
The one main thing I would not do is locally store any issue data (and for that matter most store data that related to a data store). Most of the data is important to have fresh because maybe the issue status has updated since I last retrieved that issue. All my data retrieval method would probably always make an API requests to the the latest data.
Is this against the flux "way"? Are there any issue with going about flux in this way?
I wouldn't get too hung up on the term "store". You need create application state in some way if you want your components to render something. If you need to clear that state every time a different request is made, no problem. Here's how things would flow with getIssueById(), as an example:
component calls store.getIssueById(id)
returns empty object since issue isn't in store's cache
the store calls action.fetchIssue(id)
component renders empty state
server responds with issue data and calls action.receiveIssue(data)
store caches that data and dispatches a change event
component responds to event by calling store.getIssueById(id)
the issue data is returned
component renders data
Persisting changes would be similar, with only the most recent server response being held in the store.
user interaction in component triggers action.updateIssue(modifiedIssue)
store handles action, sending changes to server
server responds with updated issue and calls action.receiveIssue(data)
...and so on with the last 4 steps from above.
As you can see, it's not really about modeling your data, just controlling how it comes and goes.
I have a simple ASPNET MVC list view which passes a custom built model object.First time through I need to go out to the server and return a list of objects and display on the view.
I am building the view to allow sorting by different columns, searching and paging, and I have written all the code for this. However every time I am going to the server and pulling the data.
Can I cut down on these DB roundtrips by using the list that I obtained first time ?
If so how do I pass it from the view back to the controller?
Viewdata, Tempdata - or pass the formcollection perhaps?
Take a look at http://www.knockoutjs.com this will give you a lot of functionality to manipulate the list in the browser and keeping the view in sync.
But it really depends on how big your list of objects is. If the quantity of data is large it is actually a more practical solution the way you implemented it already.
Actually, if you go back to your controller you'll be going to server.
I supose you really mean that you don't want to requery again your database to obtain data filtered, sorted and paginated and would like just to sort or paginate data from your model view classes with data alreay on the view.
Keep in mind that this type of operation doesn't have to be always better than requerying your database, as you'll be sending more info through the net back to the server and, usually, programatically sorting of list-like elements are operations less optimized than sorted retrievals from database.
The critical decision here will be between the cost of your database query and the size of your listview element. If your query is light and gets (or can get) many results, sorting it will be more expensive than requerying, while if your query is complex and usually throws few results then, effectively, it will be more efficient to sort data without requerying database.
Try to create a new controller method for the sort, this method will receive as a parameter your list view model class, and you'll need, somehow, to send back to your server that info. I usually use AJAX calls where I pass data as JSON to the controller.
I'm looking to build an ajax page; it's a reporting page. By default, load today's report. On the page there's a calendar control and when the user clicks on a date, reload the gridview with the corresponding data. Is it considered good practice to do the following:
1) on the first page load, query the data for the page
2) put the query result in the session object and display it in a gridview
3) if the user requests new data, get new data from the query with different parameters
4) put the result of the second query in the session object and display it
5) if the user then requests the data from the first query, get it from the session object
6) do the sorting and paging with the data held in the session.
Note: the data of each query will contain about 300-500 rows and about 15 columns. I'd like to do all this with ajax calls. What are some suggestions and pitfalls to avoid.
Thanks.
I would use Backbone.js:
Server produces report in JSON format.
Client has a Backbone.js Model for this report, which binds to the JSON endpoint.
Client renders the Report Model as a Backbone view.
Client reloads the report from server only when appropriate.
Reports from previously viewed days will still be around in the client as Backbone Model instances, so you don't need to reload from server unless the user forces. I believe this is your main concern?
You're probably still in the realm of can-do-without-a-client-side-framework, but if you plan on doing more of these pages or getting any more complex, you can go to spaghetti pretty quickly without something like Backbone.js.
PS. I just noticed this is .NET related. I know nothing about .NET so maybe there's a built-in client-side framework that can do something similar.
EDIT (updated after reading comment):
For server-side caching, I think a either a denormalized report table in the DB or a separate dedicated cache store (e.g. memcache) is a better practice than session object.
It depends though. If there was say, 1 possible report per-user per-day, and you didn't have memcache set up, and you don't want to use the DB for whatever reason, then it could make sense to store it in their session object. However, if each day's report is the same for all users, you're now caching it N times instead of 1. It could also be hard to invalidate from an external hook and the user loses their cache when they logout.
So I would probably just have a typical get-or-set pattern to try and load report from cache first, and fallback to DB. Then invalidate/update the cached report only when the user forces, or if data used to create the report has changed. AJAX call requests the report by date or however a report is identified.
Since you are hoping to use the data in Javascript Ajax scenerios it would make the most sense to create a HTTP Handler to query and return the needed data result sets on demand.
Using the session object is not a solution because it cannot be accessed asynchronously. As a result, your page would not be able to query this data to feed back to your Javascript objects (unless you created an HTTP Handler to send it back, but that would be pointless when you could just query the data in the HTTP Handler directly).
You are forgetting about windows. A client isn't a window, a client is a browser it can contain many windows/tabs. You need to make sure you are rendering/feeding the correct window. Usually i handle this by submit hidden values.
Problem is separating resuming a session / Starting a new window.
I wouldn't bother holding more than one copy of the query in the Session. The primary reason you'd want to hold it in Session is to improve the sorting/paging speed, presumably. Users expect those to be relatively fast, but choosing new dates can be slower. Plus, what's the likelihood that they'll really reload the first query?
The other answers raise good pitfalls with storing in Session in general.