From 5b5b397132b8ebad831d255c719dbfc1be8f10cb Mon Sep 17 00:00:00 2001 From: Stanislav Chzhen Date: Wed, 2 Oct 2024 20:48:58 +0300 Subject: [PATCH] Pull request 2283: AG-27492-fix-safesearch-cache Squashed commit of the following: commit c93ee78c05fae78c99796acfdfcfb4755469e37f Merge: 8019871a9 557898788 Author: Stanislav Chzhen Date: Wed Oct 2 20:41:52 2024 +0300 Merge branch 'master' into AG-27492-fix-safesearch-cache commit 8019871a93b1326cdc3475f49198bc28f194a097 Author: Stanislav Chzhen Date: Wed Oct 2 15:31:37 2024 +0300 home: fix safesearch cache --- internal/home/clients.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/internal/home/clients.go b/internal/home/clients.go index 66a44a62..5a30d6bc 100644 --- a/internal/home/clients.go +++ b/internal/home/clients.go @@ -72,10 +72,13 @@ func (clients *clientsContainer) Init( return errors.Error("clients container already initialized") } + clients.safeSearchCacheSize = filteringConf.SafeSearchCacheSize + clients.safeSearchCacheTTL = time.Minute * time.Duration(filteringConf.CacheTime) + confClients := make([]*client.Persistent, 0, len(objects)) for i, o := range objects { var p *client.Persistent - p, err = o.toPersistent(filteringConf) + p, err = o.toPersistent(clients.safeSearchCacheSize, clients.safeSearchCacheTTL) if err != nil { return fmt.Errorf("init persistent client at index %d: %w", i, err) } @@ -165,7 +168,8 @@ type clientObject struct { // toPersistent returns an initialized persistent client if there are no errors. func (o *clientObject) toPersistent( - filteringConf *filtering.Config, + safeSearchCacheSize uint, + safeSearchCacheTTL time.Duration, ) (cli *client.Persistent, err error) { cli = &client.Persistent{ Name: o.Name, @@ -201,8 +205,8 @@ func (o *clientObject) toPersistent( if o.SafeSearchConf.Enabled { err = cli.SetSafeSearch( o.SafeSearchConf, - filteringConf.SafeSearchCacheSize, - time.Minute*time.Duration(filteringConf.CacheTime), + safeSearchCacheSize, + safeSearchCacheTTL, ) if err != nil { return nil, fmt.Errorf("init safesearch %q: %w", cli.Name, err)