humanprotocol / human-protocol

Human Protocol python/js/ts Monorepo with example
https://dashboard.humanprotocol.org
MIT License
23 stars 33 forks source link

[Dashboard] Available networks endpoint #2647

Open portuu3 opened 1 month ago

portuu3 commented 1 month ago

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

  1. 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.

  2. 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.

  3. 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.

  4. 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.

eugenvoronov commented 1 week ago
  1. Define new env vars:
    • 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.
  2. Create new endpoint GET /stats/available-networks.
  3. Create new method getAvailableNetworks:
    • For each network request statisticsClient.getHMTDailyData() for the last NETWORK_USAGE_FILTER_MONTHS months.
    • For each network request statisticsClient.getEscrowStatistics() for the last month.
    • Filter the list of the networks.
    • Cache response by NETWORKS_AVAILABLE_CACHE_TTL.