From 279350e4a31d2cba893b15a467d9628f027e78af Mon Sep 17 00:00:00 2001 From: Ainar Garipov Date: Mon, 12 Apr 2021 14:10:20 +0300 Subject: [PATCH] Pull request: querylog: opt client search Updates #1273. Squashed commit of the following: commit 6c2cc73e3360ae12aaa6e2c9834fddfdba925e2b Merge: effe2230 fb72d543 Author: Ainar Garipov Date: Mon Apr 12 14:05:04 2021 +0300 Merge branch 'master' into 1273-querylog-opt commit effe22303fb2053dfe22b6242231b40f4d462735 Author: Ainar Garipov Date: Mon Apr 12 13:21:06 2021 +0300 querylog: opt client search --- internal/querylog/search.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/internal/querylog/search.go b/internal/querylog/search.go index 264b3acd..f3b1d6b6 100644 --- a/internal/querylog/search.go +++ b/internal/querylog/search.go @@ -15,7 +15,9 @@ import ( // find those records as well. func (l *queryLog) client(clientID, ip string, cache clientCache) (c *Client, err error) { cck := clientCacheKey{clientID: clientID, ip: ip} - if c = cache[cck]; c != nil { + + var ok bool + if c, ok = cache[cck]; ok { return c, nil } @@ -33,9 +35,9 @@ func (l *queryLog) client(clientID, ip string, cache clientCache) (c *Client, er return nil, err } - if cache != nil { - cache[cck] = c - } + // Cache all results, including negative ones, to prevent excessive and + // expensive client searching. + cache[cck] = c return c, nil }