From c309893d7e72a2a3d1fc5acf7992ab161c418745 Mon Sep 17 00:00:00 2001 From: spletka Date: Tue, 19 Sep 2023 17:12:55 +0200 Subject: [PATCH 1/5] (BIDS-2481) Debounced all datatables --- static/js/dashboard.js | 18 ++++++++++++------ static/js/datatable_loader.js | 4 ++-- templates/dashboard.html | 1 + templates/dashboard/tables.html | 7 +------ templates/deposits.html | 5 +++-- templates/epochs.html | 3 ++- templates/eth1DepositsLeaderboard.html | 3 ++- templates/execution/blocks.html | 8 ++------ templates/pools_rocketpool.html | 9 +++++---- templates/slot/slot.html | 9 +++++---- templates/validator/tables.html | 12 ++++++------ templates/validator/validator.html | 1 + templates/validators.html | 3 ++- templates/validators_leaderboard.html | 3 ++- templates/validators_slashings.html | 3 ++- templates/withdrawals.html | 5 +++-- 16 files changed, 51 insertions(+), 43 deletions(-) diff --git a/static/js/dashboard.js b/static/js/dashboard.js index c9e681da46..e133b3c0ec 100644 --- a/static/js/dashboard.js +++ b/static/js/dashboard.js @@ -66,7 +66,7 @@ function showValidatorHist(index) { details: false, pagingType: "simple", pageLength: 10, - ajax: "/validator/" + index + "/history", + ajax: dataTableLoader("/validator/" + index + "/history"), language: { searchPlaceholder: "Search by Epoch Number", search: "", @@ -1170,6 +1170,7 @@ $(document).ready(function () { window.dispatchEvent(new CustomEvent("dashboard_validators_set")) if (state.validators.length) { + var uRLSearchParams = new URLSearchParams([["validators", state.validators.join(",")]]) var qryStr = "?validators=" + state.validators.join(",") if (window.location.search != qryStr) { var newUrl = window.location.pathname + qryStr + window.location.hash @@ -1182,7 +1183,7 @@ $(document).ready(function () { document.querySelector("#clear-search").style.visibility = "visible" $.ajax({ - url: "/dashboard/data/validators" + qryStr, + url: dataTableLoader("/dashboard/data/validators", uRLSearchParams), success: function (result) { var t1 = Date.now() console.log(`loaded validators-data: length: ${result.data.length}, fetch: ${t1 - t0}ms`) @@ -1233,7 +1234,7 @@ $(document).ready(function () { document.querySelector("#bookmark-button").style.visibility = "visible" $.ajax({ - url: "/dashboard/data/earnings" + qryStr, + url: dataTableLoader("/dashboard/data/earnings", uRLSearchParams), success: function (result) { var t1 = Date.now() console.log(`loaded earnings: fetch: ${t1 - t0}ms`) @@ -1319,9 +1320,14 @@ $(document).ready(function () { function renderCharts() { var t0 = Date.now() - var qryStr = "?validators=" + state.validators.join(",") $.ajax({ - url: "/dashboard/data/allbalances" + qryStr + "&days=31", + url: dataTableLoader( + "/dashboard/data/allbalances", + new URLSearchParams([ + ["validators", state.validators.join(",")], + ["days", "31"], + ]) + ), success: function (result) { var t1 = Date.now() createIncomeChart(result.consensusChartData, result.executionChartData) @@ -1332,7 +1338,7 @@ $(document).ready(function () { }, }) $.ajax({ - url: "/dashboard/data/proposals" + qryStr, + url: dataTableLoader("/dashboard/data/proposals", new URLSearchParams([["validators", state.validators.join(",")]])), success: function (result) { var t1 = Date.now() if (result && result.length) { diff --git a/static/js/datatable_loader.js b/static/js/datatable_loader.js index 6a52cdee10..9007fe0ebc 100644 --- a/static/js/datatable_loader.js +++ b/static/js/datatable_loader.js @@ -6,7 +6,7 @@ * There is also a retry mechanism that retries the server request if the request fails. * @param path: Path to load the table data from the server */ -function dataTableLoader(path) { +function dataTableLoader(path, param) { const MAX_RETRIES = 5 const DEBOUNCE_DELAY = 500 const RETRY_DELAY = 1000 @@ -25,7 +25,7 @@ function dataTableLoader(path) { } const doFetch = (tableData, callback) => { - fetch(`${path}?${new URLSearchParams(tableData)}`) + fetch(`${path}?${new URLSearchParams(tableData)}&${param}`) .then((response) => { if (!response.ok) { throw new Error(`Failed with status: ${response.status}`) diff --git a/templates/dashboard.html b/templates/dashboard.html index 6804ae109a..7c9319d1cc 100644 --- a/templates/dashboard.html +++ b/templates/dashboard.html @@ -2,6 +2,7 @@ + diff --git a/templates/dashboard/tables.html b/templates/dashboard/tables.html index 437f284d06..9df4bb13ec 100644 --- a/templates/dashboard/tables.html +++ b/templates/dashboard/tables.html @@ -64,12 +64,7 @@ order: [[1, "desc"]], lengthChange: false, searching: false, - ajax: { - url: `/dashboard/data/withdrawal`, - data: function (d) { - d.validators = getValidatorString() - }, - }, + ajax: dataTableLoader(`/dashboard/data/withdrawal`, new URLSearchParams([["validators", getValidatorString()]])), pagingType: "input", pageLength: 10, language: { diff --git a/templates/deposits.html b/templates/deposits.html index 8430ad909b..ba1439c165 100644 --- a/templates/deposits.html +++ b/templates/deposits.html @@ -1,6 +1,7 @@ {{ define "js" }} + + + @@ -147,7 +148,7 @@ ordering: true, order: [[1, 'desc']], searching: true, - ajax: '/validators/deposit-leaderboard/data', + ajax: dataTableLoader('/validators/deposit-leaderboard/data'), pagingType: 'input', preDrawCallback: function () { // this does not always work.. not sure how to solve the staying tooltip diff --git a/templates/execution/blocks.html b/templates/execution/blocks.html index c6eb72a9af..5b9c780944 100644 --- a/templates/execution/blocks.html +++ b/templates/execution/blocks.html @@ -1,6 +1,7 @@ {{ define "js" }} + + + + diff --git a/templates/validators.html b/templates/validators.html index 39a1ede42e..351a477923 100644 --- a/templates/validators.html +++ b/templates/validators.html @@ -1,6 +1,7 @@ {{ define "js" }} + + + +