From 94d44b882ebebad55400b08eef23398e1a488ea8 Mon Sep 17 00:00:00 2001 From: roman Date: Fri, 19 Apr 2024 07:24:04 +0000 Subject: [PATCH] cache no candidate or ranked routes --- CHANGELOG.md | 4 ++++ router/usecase/router_usecase.go | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32596ca2e..d265c7825 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,6 +35,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ # Changelog +## v0.17.4 + +- Cache no candidate or ranked routes + ## v0.17.3 - Skip pool filtering if min osmo liquidity is zero diff --git a/router/usecase/router_usecase.go b/router/usecase/router_usecase.go index 2b1db0971..f93703779 100644 --- a/router/usecase/router_usecase.go +++ b/router/usecase/router_usecase.go @@ -71,7 +71,7 @@ var ( cacheWrite = prometheus.NewCounterVec( prometheus.CounterOpts{ Name: "sqs_routes_cache_write_total", - Help: "Total number of cache misses", + Help: "Total number of cache writes", }, []string{"route", "cache_type", "token_in", "token_out", "token_in_order_of_magnitude"}, ) @@ -291,6 +291,13 @@ func (r *routerUseCaseImpl) computeAndRankRoutesByDirectQuote(ctx context.Contex cacheWrite.WithLabelValues(requestURLPath, candidateRouteCacheLabel, tokenIn.Denom, tokenOutDenom, noOrderOfMagnitude).Inc() r.candidateRouteCache.Set(formatCandidateRouteCacheKey(tokenIn.Denom, tokenOutDenom), candidateRoutes, time.Duration(routingOptions.CandidateRouteCacheExpirySeconds)*time.Second) + } else { + // If no candidate routes found, cache them for quarter of the duration + r.candidateRouteCache.Set(formatCandidateRouteCacheKey(tokenIn.Denom, tokenOutDenom), candidateRoutes, time.Duration(routingOptions.CandidateRouteCacheExpirySeconds/4)*time.Second) + + r.rankedRouteCache.Set(formatRankedRouteCacheKey(tokenIn.Denom, tokenOutDenom, tokenInOrderOfMagnitude), candidateRoutes, time.Duration(routingOptions.RankedRouteCacheExpirySeconds/4)*time.Second) + + return nil, nil, fmt.Errorf("no candidate routes found") } // Rank candidate routes by estimating direct quotes