Home > database >  Update Blazor Page/Component after Dataset insert/Update
Update Blazor Page/Component after Dataset insert/Update

Time:05-25

I would like to update a datagrid for all site visitors on a Blazor site when a record is added to the database. In my scenario, a record is added to the database via an API controller. Now it should be automatically visible to all site users. At the moment I have a timer that queries the DB table every 1000ms. I find that burden but the database unnecessary. How would you realize that? I am very grateful for every hint.

CodePudding user response:

I've got a couple of suggestions based on the scenario you describe.

Limit Database Polling

If you've got access to the controller that's updating the database, could you perhaps have it set a flag on a singleton somewhere. When your next timer interval elapses, it only queries the database if that flag has been set (or every 15 minutes, just in case you've got a bug in setting it).

Limit External Queries

If you've got access to the controller that's performing these updates, do you necessarily have to wait for it to put the data in your database to realize the new values? Why not maintain a cache that all your visitors instead pull their data from that your controller can update with new records? Then the only load on your database is when your cache expires and it does a fresh pull and when you're electing to insert records.

  • Related