mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Change caching for Swaps APIs from 1 hour to 5 minutes (#10871)
* Change caching for the /tokens API from 1 hour to 5 minutes * Use 5 minutes caching for /topAssets and /aggregatorMetadata APIs as well
This commit is contained in:
parent
0dbd678f39
commit
a07780ab61
@ -34,7 +34,7 @@ import { calcGasTotal } from '../send/send.utils';
|
|||||||
const TOKEN_TRANSFER_LOG_TOPIC_HASH =
|
const TOKEN_TRANSFER_LOG_TOPIC_HASH =
|
||||||
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
|
'0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
|
||||||
|
|
||||||
const CACHE_REFRESH_ONE_HOUR = 3600000;
|
const CACHE_REFRESH_FIVE_MINUTES = 300000;
|
||||||
|
|
||||||
const getBaseApi = function (type, chainId = MAINNET_CHAIN_ID) {
|
const getBaseApi = function (type, chainId = MAINNET_CHAIN_ID) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@ -290,7 +290,7 @@ export async function fetchTokens(chainId) {
|
|||||||
const tokens = await fetchWithCache(
|
const tokens = await fetchWithCache(
|
||||||
tokenUrl,
|
tokenUrl,
|
||||||
{ method: 'GET' },
|
{ method: 'GET' },
|
||||||
{ cacheRefreshTime: CACHE_REFRESH_ONE_HOUR },
|
{ cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES },
|
||||||
);
|
);
|
||||||
const filteredTokens = [
|
const filteredTokens = [
|
||||||
SWAPS_CHAINID_DEFAULT_TOKEN_MAP[chainId],
|
SWAPS_CHAINID_DEFAULT_TOKEN_MAP[chainId],
|
||||||
@ -312,7 +312,7 @@ export async function fetchAggregatorMetadata(chainId) {
|
|||||||
const aggregators = await fetchWithCache(
|
const aggregators = await fetchWithCache(
|
||||||
aggregatorMetadataUrl,
|
aggregatorMetadataUrl,
|
||||||
{ method: 'GET' },
|
{ method: 'GET' },
|
||||||
{ cacheRefreshTime: CACHE_REFRESH_ONE_HOUR },
|
{ cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES },
|
||||||
);
|
);
|
||||||
const filteredAggregators = {};
|
const filteredAggregators = {};
|
||||||
for (const aggKey in aggregators) {
|
for (const aggKey in aggregators) {
|
||||||
@ -334,7 +334,7 @@ export async function fetchTopAssets(chainId) {
|
|||||||
const response = await fetchWithCache(
|
const response = await fetchWithCache(
|
||||||
topAssetsUrl,
|
topAssetsUrl,
|
||||||
{ method: 'GET' },
|
{ method: 'GET' },
|
||||||
{ cacheRefreshTime: CACHE_REFRESH_ONE_HOUR },
|
{ cacheRefreshTime: CACHE_REFRESH_FIVE_MINUTES },
|
||||||
);
|
);
|
||||||
const topAssetsMap = response.reduce((_topAssetsMap, asset, index) => {
|
const topAssetsMap = response.reduce((_topAssetsMap, asset, index) => {
|
||||||
if (validateData(TOP_ASSET_VALIDATORS, asset, topAssetsUrl)) {
|
if (validateData(TOP_ASSET_VALIDATORS, asset, topAssetsUrl)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user