Skip to content

Commit 26fd75b

Browse files
committed
add RPC& node_location cache
1 parent fe49573 commit 26fd75b

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

server/cron/nodeLocations.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { rpc } = require("../rpc");
55
const { nodeCache } = require("../client/cache");
66
const db = require("../client/mongo");
77
const { Sentry } = require("../sentry");
8-
const { NODE_LOCATIONS } = require("../constants");
8+
const { NODE_LOCATIONS, EXPIRE_48H } = require("../constants");
99

1010
const NODE_IP_REGEX = /\[::ffff:([\d.]+)\]:[\d]+/;
1111

@@ -73,8 +73,11 @@ const getNodeLocation = async ip => {
7373

7474
const doNodeLocations = async () => {
7575
console.log("Starting doNodeLocations");
76-
76+
const nodeLocations = nodeCache.get(NODE_LOCATIONS);
7777
try {
78+
if (nodeLocations) {
79+
return nodeLocations;
80+
}
7881
let peers = await getNodePeers();
7982
let results = [];
8083

@@ -106,7 +109,7 @@ const doNodeLocations = async () => {
106109
await database.collection(NODE_LOCATIONS).deleteMany({});
107110
await database.collection(NODE_LOCATIONS).insertMany(results);
108111

109-
nodeCache.set(NODE_LOCATIONS, results);
112+
nodeCache.set(NODE_LOCATIONS, results, EXPIRE_48H);
110113

111114
console.log("Done node location");
112115
} catch (err) {

server/rpc/index.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,25 @@ const allowedRpcMethods = [
3030
"uptime",
3131
"version",
3232
];
33-
33+
//@Note more cache due to 26.1
3434
const cacheSettings = {
35-
account_history: 1,
36-
account_info: 1,
37-
account_representative: 5,
38-
accounts_balances: 1,
39-
active_difficulty: 1,
40-
available_supply: 3600,
41-
block_count: 1,
42-
block_info: 1,
43-
blocks_info: 5,
44-
confirmation_history: 5,
45-
confirmation_quorum: 5,
46-
frontier_count: 5,
47-
peers: 5,
48-
pending: 5,
49-
representatives: 5,
50-
representatives_online: 5,
51-
stats: 5,
35+
account_history: 1000,
36+
account_info: 1000,
37+
account_representative: 3600,
38+
accounts_balances: 100,
39+
active_difficulty: 100,
40+
available_supply: 3600 * 10,
41+
block_count: 100,
42+
block_info: 100,
43+
blocks_info: 500,
44+
confirmation_history: 500,
45+
confirmation_quorum: 500,
46+
frontier_count: 500,
47+
peers: 3600,
48+
pending: 500,
49+
representatives: 3600 * 4,
50+
representatives_online: 3600 * 4,
51+
stats: 500,
5252
uptime: 30,
5353
version: 30,
5454
};

0 commit comments

Comments
 (0)