Skip to content

Commit

Permalink
Update AutoRefresh.js
Browse files Browse the repository at this point in the history
  • Loading branch information
difemaro committed Oct 30, 2024
1 parent f8e9908 commit bea8961
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions Extensiones/Samples/AutoRefresh_seconds/AutoRefresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,28 +117,32 @@
if (refreshInterval) {
clearTimeout(refreshInterval);
}

let dashboard = tableau.extensions.dashboardContent.dashboard;
let uniqueDataSources = new Set(); // Use a Set to store unique data sources

dashboard.worksheets.forEach(function (worksheet) {
worksheet.getDataSourcesAsync().then(function (datasources) {

// Collect all data sources from each worksheet
let worksheetPromises = dashboard.worksheets.map((worksheet) => {
return worksheet.getDataSourcesAsync().then((datasources) => {
datasources.forEach((datasource) => {
if (activeDatasourceIdList.indexOf(datasource.id) >= 0) {
uniqueDataSources.add(datasource); // Add each unique datasource to the Set
}
});

// Once all unique data sources are collected, refresh them only once
const refreshPromises = Array.from(uniqueDataSources).map((datasource) => {
return datasource.refreshAsync();
});

// Wait until all selected unique data sources are refreshed
Promise.all(refreshPromises).then(() => {
updateNextRefreshTime(interval);
refreshInterval = setTimeout(refreshDataSources, interval * 1000);
});
});
});

// Wait until all worksheets have been processed
Promise.all(worksheetPromises).then(() => {
// Refresh each unique data source only once
const refreshPromises = Array.from(uniqueDataSources).map((datasource) => {
return datasource.refreshAsync();
});

// Wait until all selected unique data sources are refreshed
Promise.all(refreshPromises).then(() => {
updateNextRefreshTime(interval);
refreshInterval = setTimeout(refreshDataSources, interval * 1000);
});
});
}
Expand Down

0 comments on commit bea8961

Please sign in to comment.