Skip to content

Commit

Permalink
only generate paths for top 50 tokens (osmosis-labs#3225)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonator authored May 7, 2024
1 parent 09e14c6 commit b3d5b51
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
3 changes: 2 additions & 1 deletion packages/server/src/queries/complex/assets/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ async function batchFetchCoingeckoCoins(keys: readonly string[]) {
}
const coingeckoCoinBatchLoader = new EdgeDataLoader(batchFetchCoingeckoCoins);

async function getActiveCoingeckoCoins() {
/** Set of active CoinGecko IDs that CoinGecko has data for (is "active"). */
export async function getActiveCoingeckoCoins() {
return await cachified({
cache: assetMarketCache,
ttl: 1000 * 60 * 60, // 1 hour
Expand Down
41 changes: 35 additions & 6 deletions packages/web/pages/assets/[denom].tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { Dec } from "@keplr-wallet/unit";
import {
CoingeckoCoin,
getActiveCoingeckoCoins,
getAsset,
getAssetMarketActivity,
getTokenInfo,
queryCoingeckoCoin,
RichTweet,
sort,
TokenCMSData,
Twitter,
} from "@osmosis-labs/server";
Expand Down Expand Up @@ -560,23 +563,49 @@ const TokenChart = observer(() => {

export default AssetInfoPage;

/** Number of assets, sorted by volume, to generate static paths for. */
const TOP_VOLUME_ASSETS_COUNT = 50;

/**
* Prerender all the denoms, we can also filter this value to reduce
* build time
* Prerender important denoms. See function body for what we consider "important".
*/
export const getStaticPaths = async (): Promise<GetStaticPathsResult> => {
let paths: { params: { denom: string } }[] = [];

const currencies = ChainList.map((info) => info.keplrChain.currencies).reduce(
(a, b) => [...a, ...b]
const assets = AssetLists.flatMap((list) => list.assets);
const activeCoinGeckoIds = await getActiveCoingeckoCoins();

const importantAssets = assets.filter(
(asset) =>
asset.verified &&
!asset.unstable &&
!asset.preview &&
// Prevent repeated "coin not found" errors from CoinGecko coin query downsteram
asset.coingeckoId &&
activeCoinGeckoIds.has(asset.coingeckoId)
);

const marketAssets = (
await Promise.all(
importantAssets.map((asset) =>
getAssetMarketActivity(asset).then((activity) => ({
...activity,
...asset,
}))
)
)
).filter((asset): asset is NonNullable<typeof asset> => asset !== undefined);

const topVolumeAssets = sort(marketAssets, "volume7d").slice(
0,
TOP_VOLUME_ASSETS_COUNT
);
/**
* Add cache for all available currencies
*/
paths = currencies.map((currency) => ({
paths = topVolumeAssets.map((asset) => ({
params: {
denom: currency.coinDenom,
denom: asset.symbol,
},
}));

Expand Down

0 comments on commit b3d5b51

Please sign in to comment.