Page 1 of 1

Refresh single table in all clients

PostPosted: Tue Jan 24, 2023 6:50 pm
by steve1376656734
Hi,

I have an stored procedure that updates a single table in the DB. The process may update any number of records each time it runs and it is run from within a Servoy program.

Is there a way for the client that has just run this program to signal all attached clients that their cached records for that table (and only that table) are now invalid and should be refreshed? I can see that the entire data cache can be flushed from the Servoy admin page but I want to do it for a single table and from within a Servoy program.

Thanks
Steve

Re: Refresh single table in all clients

PostPosted: Wed Jan 25, 2023 12:29 am
by swingman
Maybe this will work: if you have a way of recognising the updated records, you can load them into a foundSet and refresh this foundSet from the database using the databaseManager...

Re: Refresh single table in all clients

PostPosted: Wed Jan 25, 2023 9:16 am
by mboegem
Hi Steve,

to signal all clients to refresh the data of a certain table, you can use:
Code: Select all
plugins.rawSQL.flushAllClientsCache(_sServerName, _sTableName)

Depending on the usage of the table, it can be a heavy operation.

Another way to make sure users see the latest data is by using:
Code: Select all
databaseManager.refreshRecordFromDatabase(_fs, -1)

Downside of this function is that it will only refresh the records for the client on which is it is executed.
I've used this in the past for refreshing data coming from a database view.
So each time the user entered a form using this view, data would be refreshed.
Because the datasource (db view) was immutable anyway, this method worked fine for the situation.

Hope this helps

Re: Refresh single table in all clients

PostPosted: Wed Jan 25, 2023 10:38 am
by steve1376656734
@Christian - that would work but the table has 2 million records and I have no way of knowing which records are updated so even just loading the foundset would be an expensive operation

mboegem wrote:
Code: Select all
plugins.rawSQL.flushAllClientsCache(_sServerName, _sTableName)


That is perfect as each client would only have a few records loaded from that table at a time so it would be trivial for their client to reload them - thanks Mark

Re: Refresh single table in all clients

PostPosted: Wed Jan 25, 2023 11:01 am
by swingman
I have a similar situation, but I have a field in the table called needs refresh and the outside process flags the report that servoy needs to load.