Skip to content

Commit 9d2c54f

Browse files
committed
only save requests on change
1 parent 502fd9d commit 9d2c54f

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

assets_js_bitrequest_monitors.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ function get_requeststates(trigger, active_requests) {
107107
requeststates = statuscache.requeststates;
108108
if (cachetime > 30000 || empty_obj(requeststates)) { //check if cached crypto rates are expired (check every 30 seconds on page refresh or when opening request page)
109109
active_requests.addClass("scan");
110-
br_remove_session("txstatus"); // remove cached transactions
111110
getinputs(request_data, d_lay);
112111
return
113112
}
@@ -138,19 +137,30 @@ function get_requeststates(trigger, active_requests) {
138137
return
139138
}
140139
if (!empty_obj(glob_let.statuspush)) {
140+
const tx_states = br_get_session("txstatus", true);
141+
if (tx_states) {
142+
const txs = tx_states.requeststates,
143+
txid = sha_sub(JSON.stringify(txs), 15), // hash arrays to compare for changes
144+
new_tx_id = sha_sub(JSON.stringify(glob_let.statuspush), 15);
145+
if (txid !== new_tx_id) { // check for updates
146+
// Only save on status updates
147+
saverequests();
148+
}
149+
} else {
150+
saverequests();
151+
}
141152
const statusobject = {
142153
"timestamp": now(),
143154
"requeststates": glob_let.statuspush
144155
};
145156
br_set_session("txstatus", statusobject, true);
146-
saverequests();
147157
clearscan();
148158
}
149159
}
150160

151161
// Retrieves input data for requests
152162
function getinputs(rd, dl) {
153-
const rdo = tx_data(rd); // fetchblocks.js
163+
const rdo = tx_data(rd);
154164
if (rdo.pending === "scanning" || rdo.pending === "polling") {
155165
if (dl) {
156166
const delay = 10000,
@@ -174,7 +184,7 @@ function getinputs(rd, dl) {
174184
const transactionlist = rdo.transactionlist;
175185
if (transactionlist) {
176186
transactionlist.find("li").each(function(i) {
177-
glob_let.tx_list.push($(this).data("txhash"));
187+
glob_let.tx_list.push($(this).data("txhash")); //index transaction id's
178188
});
179189
api_callback(rdo);
180190
}
@@ -221,6 +231,11 @@ function continue_select(rd, api_data, rdo) {
221231

222232
function continue_select_api(rd, api_data, rdo) {
223233
const api_name = api_data.name;
234+
if (rdo.source === "addr_polling") {
235+
glob_let.rpc_attempts = {}
236+
continue_select(rd, api_data, rdo);
237+
return
238+
}
224239
if (api_name === "mymonero api") {
225240
monero_fetch_init(rd, api_data, rdo);
226241
return
@@ -265,11 +280,6 @@ function continue_select_api(rd, api_data, rdo) {
265280
insight_fetch_dash(rd, api_data, rdo);
266281
return
267282
}
268-
if (rdo.source === "addr_polling") {
269-
glob_let.rpc_attempts = {}
270-
continue_select(rd, api_data, rdo);
271-
return
272-
}
273283
api_callback(rdo);
274284
}
275285

@@ -417,6 +427,7 @@ function handle_rpc_fails(rd, rdo, error_obj, api_data, l2) {
417427
error_data = get_api_error_data(error_obj),
418428
timeout = rdo.timeout,
419429
cachetime = rdo.cachetime;
430+
420431
function next_proxy(type) { // try next proxy
421432
if (type === "api_fail" && (error_data.apikey || glob_let.apikey_fails)) return false; // only try next proxy if api key is expired or missing
422433
if (get_next_proxy()) {
@@ -745,8 +756,9 @@ function data_title(dat) {
745756
lc_val = dat.ccval * lc_ccrate,
746757
cc_upper = dat.ccsymbol ? dat.ccsymbol.toUpperCase() : dat.ccsymbol,
747758
lc_upper = lcsymbol ? lcsymbol.toUpperCase() : lcsymbol,
748-
localrate = lc_upper === "USD" ? "" : cc_upper + "-" + lc_upper + ": " + lc_ccrate.toFixed(6) + "\n" + lc_upper + "-USD: " + lc_usd_rate.toFixed(2),
749-
historic_dat = "Historic data (" + fulldateformat(new Date(timestamp - glob_const.timezone), langcode) + "):\n" +
759+
localrate = lc_upper === "USD" ? "" : cc_upper + "-" + lc_upper + ": " + lc_ccrate.toFixed(6) + "\n" + lc_upper + "-USD: " + lc_usd_rate.toFixed(2);
760+
// set historic data
761+
historic_dat = "Historic data (" + fulldateformat(new Date(timestamp - glob_const.timezone), langcode) + "):\n" +
750762
"Fiatvalue: " + lc_val.toFixed(2) + " " + lc_upper + "\n" +
751763
cc_upper + "-USD: " + price.toFixed(6) + "\n" +
752764
localrate + "\n" +

assets_js_lib_global_queries.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,11 @@ const br_bipobj = br_get_local("bpdat", true),
122122
"socket_attempt": {},
123123
"api_attempt": {},
124124
"rpc_attempts": {},
125-
"apikey_fails": false,
126-
"statuspush": [],
125+
"proxy_attempts": {},
127126
"tx_list": [],
127+
"statuspush": [],
128+
"l2_fetched": {},
129+
"apikey_fails": false,
128130
"changes": {}, //bip39
129131
"test_derive": true,
130132
"phrasearray": null,
@@ -148,7 +150,6 @@ const br_bipobj = br_get_local("bpdat", true),
148150
"init": br_init,
149151
"io": br_io,
150152
"new_address": false, // prevent double address entries
151-
"proxy_attempts": {},
152153
"sockets": {},
153154
"pinging": {},
154155
"currencyscan": null,
@@ -183,9 +184,7 @@ const br_bipobj = br_get_local("bpdat", true),
183184
"socket": 0,
184185
"proxy": 0
185186
},
186-
"overflow_detected": false,
187-
"l2_fetched": {}
188-
187+
"overflow_detected": false
189188
}
190189

191190
// Global helpers

0 commit comments

Comments
 (0)