Skip to content

Commit

Permalink
feat: increase cache age, reduce interval update frequency (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrsirapop authored Oct 25, 2024
1 parent 75594a7 commit 4f8a925
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions methods/tvl/getTVL.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const { isNumber, toNumber } = require('../../utils/number');
const { timeDiff } = require('../../utils/time');

const CACHE_AGE_SECONDS = 60 * 60;
const IBC_CHANNELS_UPDATE_INTERVAL_SECONDS = 240 * 60;
const IBC_CHANNELS_UPDATE_INTERVAL_SECONDS = 720 * 60;

const normalizeCacheId = id => isString(id) ? split(id, { delimiter: '/' }).join('_') : undefined;
const generateDenom = d => `${d.decimals === 6 ? 'u' : ''}${d.symbol.toLowerCase()}${d.decimals === 18 ? '-wei' : ''}`;
Expand Down Expand Up @@ -174,7 +174,7 @@ module.exports = async params => {
let escrow_addresses;
let source_escrow_addresses;
if (toArray(prefix_chain_ids).length > 0 && id !== 'axelarnet') {
for (let i = 0; i < 2; i++) {
for (let i = 0; i < 1; i++) {
const { data } = { ...await read(IBC_CHANNEL_COLLECTION, {
bool: {
must: [{ match: { state: 'STATE_OPEN' } }],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "axelarscan-api",
"version": "0.0.100",
"version": "0.0.101",
"description": "Axelarscan API",
"main": "index.js",
"scripts": {
Expand Down
6 changes: 6 additions & 0 deletions services/interval-update/updateStats.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
const moment = require('moment');

const METHODS = require('../../methods');

module.exports = async () => {
const minute = moment().minutes();
// run every 10 minutes
if (minute % 10 !== 0) return;

await Promise.all(['transfersStats', 'transfersChart', 'transfersCumulativeVolume', 'transfersTotalVolume', 'transfersTotalFee', 'transfersTotalActiveUsers', 'transfersTopUsers', 'transfersTopUsersByVolume', 'GMPStats', 'GMPStatsAVGTimes', 'GMPChart', 'GMPCumulativeVolume', 'GMPTotalVolume', 'GMPTotalFee', 'GMPTotalActiveUsers', 'GMPTopUsers', 'GMPTopITSUsers', 'GMPTopITSUsersByVolume', 'GMPTopITSAssets', 'GMPTopITSAssetsByVolume'].map(d => new Promise(async resolve => {
switch (d) {
case 'transfersTopUsers':
Expand Down
6 changes: 3 additions & 3 deletions services/interval-update/updateTVL.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const { toArray } = require('../../utils/parser');

module.exports = async params => {
const minute = moment().minutes();
// run every 10 minutes
if (minute % 10 !== 0) return;
// run every 15 minutes
if (minute % 15 !== 0) return;
const data = {};
for (const d of toArray(_.concat(await getAssetsList(), await getITSAssetsList())).filter(d => !params?.id || d.id === params.id).filter(d => params?.id || (minute % 20 === 0 ? d.id.startsWith('0x') : !d.id.startsWith('0x')))) {
for (const d of toArray(_.concat(await getAssetsList(), await getITSAssetsList())).filter(d => !params?.id || d.id === params.id).filter(d => params?.id || (minute % 30 === 0 ? d.id.startsWith('0x') : !d.id.startsWith('0x')))) {
data[d.id] = await getTVL({ asset: d.id, force_update: true });
}
return data;
Expand Down
2 changes: 1 addition & 1 deletion terraform/devnet-amplifier/variables.tf.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ variable "log_level" {

variable "app_version" {
description = "App version, same as docker image version"
default = "0.0.100"
default = "0.0.101"
validation {
error_message = "Must be valid semantic version. $Major.$Minor.$Patch"
condition = can(regex("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$", var.app_version))
Expand Down
2 changes: 1 addition & 1 deletion terraform/devnet-verifiers/variables.tf.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ variable "log_level" {

variable "app_version" {
description = "App version, same as docker image version"
default = "0.0.100"
default = "0.0.101"
validation {
error_message = "Must be valid semantic version. $Major.$Minor.$Patch"
condition = can(regex("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$", var.app_version))
Expand Down
2 changes: 1 addition & 1 deletion terraform/mainnet/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ resource "aws_apigatewayv2_api_mapping" "mainnet" {

resource "aws_cloudwatch_event_rule" "schedule" {
name = "${var.package_name}-${var.environment}-rule"
schedule_expression = "cron(*/2 * * * ? *)"
schedule_expression = "cron(*/5 * * * ? *)"
}

resource "aws_cloudwatch_event_target" "target" {
Expand Down
2 changes: 1 addition & 1 deletion terraform/mainnet/variables.tf.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ variable "log_level" {

variable "app_version" {
description = "App version, same as docker image version"
default = "0.0.100"
default = "0.0.101"
validation {
error_message = "Must be valid semantic version. $Major.$Minor.$Patch"
condition = can(regex("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$", var.app_version))
Expand Down
2 changes: 1 addition & 1 deletion terraform/stagenet/variables.tf.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ variable "log_level" {

variable "app_version" {
description = "App version, same as docker image version"
default = "0.0.100"
default = "0.0.101"
validation {
error_message = "Must be valid semantic version. $Major.$Minor.$Patch"
condition = can(regex("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$", var.app_version))
Expand Down
2 changes: 1 addition & 1 deletion terraform/testnet/variables.tf.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ variable "log_level" {

variable "app_version" {
description = "App version, same as docker image version"
default = "0.0.100"
default = "0.0.101"
validation {
error_message = "Must be valid semantic version. $Major.$Minor.$Patch"
condition = can(regex("^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-((?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\\.(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$", var.app_version))
Expand Down
2 changes: 1 addition & 1 deletion utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const getAxelarConfig = async (env = ENVIRONMENT, forceCache = false) => {
let response;
const cacheId = 'config';
const { data, updated_at } = { ...(!forceCache ? await get(AXELAR_CONFIG_COLLECTION, cacheId) : undefined) };
if (data && timeDiff(updated_at) < 600) response = toJson(data);
if (data && timeDiff(updated_at) < 900) response = toJson(data);
else {
response = await request(`https://axelar-${env}.s3.us-east-2.amazonaws.com/configs/${env}-config-1.x.json`);
if (response?.tokenAddressToAsset) delete response.tokenAddressToAsset;
Expand Down

0 comments on commit 4f8a925

Please sign in to comment.