Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bids 2481/all datatables should be debounced #2567

Merged
merged 6 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion static/js/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: "",
Expand Down
11 changes: 8 additions & 3 deletions static/js/datatable_loader.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/**
* function dataTableLoader(path)
* function dataTableLoader(path, param, dataSrc)
* used to create an ajax function for a DataTable.
* This function is used to load data from the server for a DataTable.
* It is debounced to avoid multiple requests to the server when the user clicks on the pagination buttons.
* 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
* @param param: Additional parameters to be passed to the server
* @param dataSrc: Function to be called on the data returned from the server
*/
function dataTableLoader(path) {
function dataTableLoader(path, param, dataSrc) {
const MAX_RETRIES = 5
const DEBOUNCE_DELAY = 500
const RETRY_DELAY = 1000
Expand All @@ -25,14 +27,17 @@ function dataTableLoader(path) {
}

const doFetch = (tableData, callback) => {
fetch(`${path}?${$.param(tableData)}`)
fetch(`${path}?${$.param(tableData)}&${param}`)
.then((response) => {
if (!response.ok) {
throw new Error(`Failed with status: ${response.status}`)
}
return response.json()
})
.then((data) => {
if (typeof dataSrc === "function") {
data = dataSrc({ data })
}
callback(data)
})
.catch((err) => {
Expand Down
1 change: 1 addition & 0 deletions templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<script type="text/javascript" src="/js/datatables.min.js"></script>
<script type="text/javascript" src="/js/datatable_input.js"></script>
<script type="text/javascript" src="/js/datatable_loader.js"></script>
<script src="/js/highcharts/highstock.min.js"></script>
<script src="/js/highcharts/exporting.min.js"></script>
<script src="/js/highcharts/offline-exporting.min.js"></script>
Expand Down
7 changes: 1 addition & 6 deletions templates/dashboard/tables.html
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
5 changes: 3 additions & 2 deletions templates/deposits.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{ define "js" }}
<script type="text/javascript" src="/js/datatables.min.js"></script>
<script type="text/javascript" src="/js/datatable_input.js"></script>
<script type="text/javascript" src="/js/datatable_loader.js"></script>
<script type="text/javascript" src="/js/highcharts/highstock.min.js"></script>
<script type="text/javascript" src="/js/highcharts/highcharts-global-options.js"></script>
<script>
Expand All @@ -22,7 +23,7 @@
},
order: [[4, 'desc']],
searching: true,
ajax: '/validators/initiated-deposits/data',
ajax: dataTableLoader('/validators/initiated-deposits/data'),
pagingType: 'input',
preDrawCallback: function() {
// this does not always work.. not sure how to solve the staying tooltip
Expand Down Expand Up @@ -58,7 +59,7 @@
},
order: [[0, "desc"]],
searching: true,
ajax: "/validators/included-deposits/data",
ajax: dataTableLoader("/validators/included-deposits/data"),
pagingType: "input",
language: {
searchPlaceholder: "Slot | Validator Key | Withdrawal Credentials | ENS address",
Expand Down
3 changes: 2 additions & 1 deletion templates/epochs.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{{ define "js" }}
<script type="text/javascript" src="/js/datatables.min.js"></script>
<script type="text/javascript" src="/js/datatable_input.js"></script>
<script type="text/javascript" src="/js/datatable_loader.js"></script>
<script>
$(document).ready(function () {
$("#epochs").DataTable({
processing: true,
serverSide: true,
ordering: false,
searching: true,
ajax: "/epochs/data",
ajax: dataTableLoader("/epochs/data"),
pagingType: "input",
stateSave: true,
stateSaveCallback: function (settings, data) {
Expand Down
3 changes: 2 additions & 1 deletion templates/eth1DepositsLeaderboard.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{ define "js" }}
<script type="text/javascript" src="/js/datatables.min.js"></script>
<script type="text/javascript" src="/js/datatable_input.js"></script>
<script type="text/javascript" src="/js/datatable_loader.js"></script>
<script src="/js/highcharts/highcharts.min.js"></script>
<script src="/js/highcharts/annotations.min.js"></script>
<script src="/js/highcharts/data.min.js"></script>
Expand Down Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions templates/execution/blocks.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{ define "js" }}
<script type="text/javascript" src="/js/datatables.min.js"></script>
<script type="text/javascript" src="/js/datatable_input.js"></script>
<script type="text/javascript" src="/js/datatable_loader.js"></script>

<script>
// live update for current block id
Expand Down Expand Up @@ -35,12 +36,7 @@
serverSide: true,
ordering: false,
searching: false,
ajax: {
url: "/blocks/data",
data: function (d) {
return $.extend({}, d, { recordsTotal: highestID })
},
},
ajax: dataTableLoader("/blocks/data", new URLSearchParams([["recordsTotal", highestID]])),
pageLength: 10,
pagingType: "input",
language: {
Expand Down
9 changes: 5 additions & 4 deletions templates/pools_rocketpool.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
<script type="text/javascript" src="/js/datatablesNew.min.js"></script>
<script type="text/javascript" src="/js/datatables.min.js"></script>
<script type="text/javascript" src="/js/datatable_input.js"></script>
<script type="text/javascript" src="/js/datatable_loader.js"></script>
<script>
$("#minipools").DataTable({
ajax: "/pools/rocketpool/data/minipools",
ajax: dataTableLoader("/pools/rocketpool/data/minipools"),
language: {
info: "_TOTAL_ entries",
infoEmpty: "No entries match",
Expand Down Expand Up @@ -93,7 +94,7 @@
})

$("#nodes").DataTable({
ajax: "/pools/rocketpool/data/nodes",
ajax: dataTableLoader("/pools/rocketpool/data/nodes"),
language: {
info: "_TOTAL_ entries",
infoEmpty: "No entries match",
Expand Down Expand Up @@ -194,7 +195,7 @@
})

$("#dao_members").DataTable({
ajax: "/pools/rocketpool/data/dao_members",
ajax: dataTableLoader("/pools/rocketpool/data/dao_members"),
language: {
info: "_TOTAL_ entries",
infoEmpty: "No entries match",
Expand Down Expand Up @@ -271,7 +272,7 @@
})

$("#dao_proposals").DataTable({
ajax: "/pools/rocketpool/data/dao_proposals",
ajax: dataTableLoader("/pools/rocketpool/data/dao_proposals"),
language: {
info: "_TOTAL_ entries",
infoEmpty: "No entries match",
Expand Down
9 changes: 5 additions & 4 deletions templates/slot/slot.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<script type="text/javascript" src="/js/datatables.min.js"></script>
<script type="text/javascript" src="/js/datatable_input.js"></script>
<script type="text/javascript" src="/js/datatable_loader.js"></script>

<script>
function getInfoElementAttestations (text, color) {
Expand Down Expand Up @@ -145,7 +146,7 @@
serverSide: true,
ordering: false,
searching: false,
ajax: "/slot/" + slotNumber + "/deposits",
ajax: dataTableLoader("/slot/" + slotNumber + "/deposits"),
pageLength: 10,
pagingType: "input",
language: {
Expand Down Expand Up @@ -199,7 +200,7 @@
return JSON.parse(localStorage.getItem("DataTables_" + settings.sInstance))
},
searching: true,
ajax: "/slot/" + slotNumber + "/votes",
ajax: dataTableLoader("/slot/" + slotNumber + "/votes"),
pageLength: 16,
pagingType: "input",
language: {
Expand Down Expand Up @@ -239,7 +240,7 @@
info: false,
// stateSave: true,
searching: false,
ajax: "/slot/" + slotNumber + "/withdrawals",
ajax: dataTableLoader("/slot/" + slotNumber + "/withdrawals"),
paging: false,
// deferLoading: true,
pageLength: 10,
Expand All @@ -265,7 +266,7 @@
info: false,
// stateSave: true,
searching: false,
ajax: "/slot/" + slotNumber + "/blsChange",
ajax: dataTableLoader("/slot/" + slotNumber + "/blsChange"),
paging: false,
// deferLoading: true,
pageLength: 10,
Expand Down
17 changes: 7 additions & 10 deletions templates/validator/tables.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
order: [[0, 'desc']],
lengthChange: false,
searching: false,
ajax: '/validator/' + index + '/proposedblocks',
ajax: dataTableLoader('/validator/' + index + '/proposedblocks'),
pagingType: 'input',
pageLength: 10,
language: {
Expand Down Expand Up @@ -127,7 +127,7 @@
order: [[0, 'desc']],
lengthChange: false,
searching: false,
ajax: '/validator/' + index + '/attestations',
ajax: dataTableLoader('/validator/' + index + '/attestations'),
pagingType: 'input',
pageLength: 10,
language: {
Expand Down Expand Up @@ -196,9 +196,7 @@
order: [[0, 'desc']],
lengthChange: false,
searching: false,
ajax: {
url: `/validator/${index}/withdrawals`,
dataSrc: function ( { data } ) {
ajax: dataTableLoader(`/validator/${index}/withdrawals`, "", function ( {data} ) {
// add the estimate row if it exists
{{ if .NextWithdrawalRow }}
let row = {{.NextWithdrawalRow}}
Expand All @@ -207,8 +205,7 @@
}
{{ end }}
return data
},
},
}),
D13ce marked this conversation as resolved.
Show resolved Hide resolved
pagingType: 'input',
pageLength: 10,
language: {
Expand Down Expand Up @@ -279,7 +276,7 @@
return JSON.parse(localStorage.getItem("DataTables_" + settings.sInstance))
},
searching: false,
ajax: '/validator/' + index + '/sync',
ajax: dataTableLoader('/validator/' + index + '/sync'),
pagingType: 'input',
pageLength: 10,
language: {
Expand Down Expand Up @@ -358,7 +355,7 @@
return JSON.parse(localStorage.getItem("DataTables_" + settings.sInstance))
},
searching: false,
ajax: '/validator/' + index + '/slashings',
ajax: dataTableLoader('/validator/' + index + '/slashings'),
pagingType: 'input',
pageLength: 10,
language: {
Expand Down Expand Up @@ -639,7 +636,7 @@ <h6 class="">This table displays the deposits received and processed by the beac
stateLoadCallback: function (settings) {
return JSON.parse(localStorage.getItem("DataTables_" + settings.sInstance))
},
ajax: '/validator/' + index + '/history',
ajax: dataTableLoader('/validator/' + index + '/history'),
pagingType: 'input',
pageLength: 10,
language: {
Expand Down
1 change: 1 addition & 0 deletions templates/validator/validator.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
{{ if and (ne .Status "deposited") (ne .Status "deposited_invalid") }}
<script type="text/javascript" src="/js/datatables.min.js"></script>
<script type="text/javascript" src="/js/datatable_input.js"></script>
<script type="text/javascript" src="/js/datatable_loader.js"></script>
<script src="/js/highcharts/highstock.min.js"></script>
<script src="/js/highcharts/exporting.min.js"></script>
<script src="/js/highcharts/offline-exporting.min.js"></script>
Expand Down
3 changes: 2 additions & 1 deletion templates/validators.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{ define "js" }}
<script type="text/javascript" src="/js/datatables.min.js"></script>
<script type="text/javascript" src="/js/datatable_input.js"></script>
<script type="text/javascript" src="/js/datatable_loader.js"></script>
<script>
var validatorsDataTable;
const totalCount = {{.TotalCount}};
Expand Down Expand Up @@ -116,7 +117,7 @@ <h6 class="dropdown-header"><span>Filter state</span> <span><span class="text-su
stateLoadCallback: function (settings) {
return JSON.parse(localStorage.getItem("DataTables_" + settings.sInstance))
},
ajax: '/validators/data?filterByState=' + state,
ajax: dataTableLoader('/validators/data', new URLSearchParams([["filterByState", state]])),
LuccaBitfly marked this conversation as resolved.
Show resolved Hide resolved
pagingType: 'input',
language: {
paginate: {
Expand Down
3 changes: 2 additions & 1 deletion templates/validators_leaderboard.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{ define "js" }}
<script type="text/javascript" src="/js/datatables.min.js"></script>
<script type="text/javascript" src="/js/datatable_input.js"></script>
<script type="text/javascript" src="/js/datatable_loader.js"></script>
<script>
$(document).ready(function () {
var tblOpts = {
Expand All @@ -16,7 +17,7 @@
stateLoadCallback: function (settings) {
return JSON.parse(localStorage.getItem("DataTables_" + settings.sInstance))
},
ajax: "/validators/leaderboard/data",
ajax: dataTableLoader("/validators/leaderboard/data"),
pagingType: "input",
language: {
searchPlaceholder: "Search by Public Key / Index / Name",
Expand Down
3 changes: 2 additions & 1 deletion templates/validators_slashings.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{ define "js" }}
<script type="text/javascript" src="/js/datatables.min.js"></script>
<script type="text/javascript" src="/js/datatable_input.js"></script>
<script type="text/javascript" src="/js/datatable_loader.js"></script>
<script>
$("#slashings").DataTable({
processing: true,
Expand All @@ -17,7 +18,7 @@
},
paging: true,
pagingType: "input",
ajax: "/validators/slashings/data",
ajax: dataTableLoader("/validators/slashings/data"),
language: {
// searchPlaceholder: 'Search by Epoch Number',
// search: '',
Expand Down
5 changes: 3 additions & 2 deletions templates/withdrawals.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{{ define "js" }}
<script type="text/javascript" src="/js/datatables.min.js"></script>
<script type="text/javascript" src="/js/datatable_input.js"></script>
<script type="text/javascript" src="/js/datatable_loader.js"></script>
<script type="text/javascript" src="/js/highcharts/highstock.min.js"></script>
<script type="text/javascript" src="/js/highcharts/highcharts-global-options.js"></script>
<script>
Expand Down Expand Up @@ -54,7 +55,7 @@
},
order: [[2, "desc"]],
searching: true,
ajax: "/validators/withdrawals/data",
ajax: dataTableLoader("/validators/withdrawals/data"),
pageLength: 10,
pagingType: "input",
preDrawCallback: function () {
Expand Down Expand Up @@ -127,7 +128,7 @@
},
order: [[2, "desc"]],
searching: true,
ajax: "/validators/withdrawals/bls",
ajax: dataTableLoader("/validators/withdrawals/bls"),
pageLength: 10,
pagingType: "input",
preDrawCallback: function () {
Expand Down
Loading