Skip to content

Commit

Permalink
add RPC& node_location cache
Browse files Browse the repository at this point in the history
  • Loading branch information
tombertrand committed Mar 4, 2024
1 parent fe49573 commit 26fd75b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
9 changes: 6 additions & 3 deletions server/cron/nodeLocations.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { rpc } = require("../rpc");
const { nodeCache } = require("../client/cache");
const db = require("../client/mongo");
const { Sentry } = require("../sentry");
const { NODE_LOCATIONS } = require("../constants");
const { NODE_LOCATIONS, EXPIRE_48H } = require("../constants");

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

Expand Down Expand Up @@ -73,8 +73,11 @@ const getNodeLocation = async ip => {

const doNodeLocations = async () => {
console.log("Starting doNodeLocations");

const nodeLocations = nodeCache.get(NODE_LOCATIONS);
try {
if (nodeLocations) {
return nodeLocations;
}
let peers = await getNodePeers();
let results = [];

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

nodeCache.set(NODE_LOCATIONS, results);
nodeCache.set(NODE_LOCATIONS, results, EXPIRE_48H);

console.log("Done node location");
} catch (err) {
Expand Down
36 changes: 18 additions & 18 deletions server/rpc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@ const allowedRpcMethods = [
"uptime",
"version",
];

//@Note more cache due to 26.1
const cacheSettings = {
account_history: 1,
account_info: 1,
account_representative: 5,
accounts_balances: 1,
active_difficulty: 1,
available_supply: 3600,
block_count: 1,
block_info: 1,
blocks_info: 5,
confirmation_history: 5,
confirmation_quorum: 5,
frontier_count: 5,
peers: 5,
pending: 5,
representatives: 5,
representatives_online: 5,
stats: 5,
account_history: 1000,
account_info: 1000,
account_representative: 3600,
accounts_balances: 100,
active_difficulty: 100,
available_supply: 3600 * 10,
block_count: 100,
block_info: 100,
blocks_info: 500,
confirmation_history: 500,
confirmation_quorum: 500,
frontier_count: 500,
peers: 3600,
pending: 500,
representatives: 3600 * 4,
representatives_online: 3600 * 4,
stats: 500,
uptime: 30,
version: 30,
};
Expand Down

0 comments on commit 26fd75b

Please sign in to comment.