Open portuu3 opened 1 month ago
GET /stats/available-networks
.getAvailableNetworks
:
statisticsClient.getHMTDailyData()
for the last NETWORK_USAGE_FILTER_MONTHS
months. statisticsClient.getEscrowStatistics()
for the last month.NETWORKS_AVAILABLE_CACHE_TTL
.
Description Create a new API endpoint that returns the list of available networks. The list should exclude any networks that have not been used in the last x months, where x is defined by an environment variable. The response should also be cached, with the Time-to-Live (TTL) duration passed as another environment variable. We should not cache data from subgraph for disabled networks. Criteria to consider a network without usage: Have at least 1 escrow created in the last month and 5 HMT transfers in the last X months.
Motivation This feature is necessary to improve the performance and relevancy of the network data we provide. By filtering out inactive networks and caching the response, we can reduce unnecessary processing and API calls, leading to better resource management and response times for clients.
Implementation details
Filtering: Implement a mechanism to retrieve networks and filter out those without usage in the last x months. The x value should be configurable via an environment variable.
Caching: Cache the response of this endpoint, setting the cache expiration to a TTL (Time-to-Live) value defined by another environment variable. Ensure that data from subgraphs for disabled networks is not cached.
Environment Variables: Define two new environment variables: NETWORK_USAGE_FILTER_MONTHS: Number of months to use for filtering out networks with no usage. NETWORKS_AVAILABLE_CACHE_TTL: The TTL for caching the response.
Response: Return a list of networks that meet the filtering criteria. Ensure that once the TTL expires, the cache is invalidated and the network list is re-generated upon the next request.