Pull request 2283: AG-27492-fix-safesearch-cache
Squashed commit of the following: commit c93ee78c05fae78c99796acfdfcfb4755469e37f Merge:8019871a9
557898788
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Oct 2 20:41:52 2024 +0300 Merge branch 'master' into AG-27492-fix-safesearch-cache commit8019871a93
Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Oct 2 15:31:37 2024 +0300 home: fix safesearch cache
This commit is contained in:
parent
5578987884
commit
5b5b397132
|
@ -72,10 +72,13 @@ func (clients *clientsContainer) Init(
|
||||||
return errors.Error("clients container already initialized")
|
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))
|
confClients := make([]*client.Persistent, 0, len(objects))
|
||||||
for i, o := range objects {
|
for i, o := range objects {
|
||||||
var p *client.Persistent
|
var p *client.Persistent
|
||||||
p, err = o.toPersistent(filteringConf)
|
p, err = o.toPersistent(clients.safeSearchCacheSize, clients.safeSearchCacheTTL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("init persistent client at index %d: %w", i, err)
|
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.
|
// toPersistent returns an initialized persistent client if there are no errors.
|
||||||
func (o *clientObject) toPersistent(
|
func (o *clientObject) toPersistent(
|
||||||
filteringConf *filtering.Config,
|
safeSearchCacheSize uint,
|
||||||
|
safeSearchCacheTTL time.Duration,
|
||||||
) (cli *client.Persistent, err error) {
|
) (cli *client.Persistent, err error) {
|
||||||
cli = &client.Persistent{
|
cli = &client.Persistent{
|
||||||
Name: o.Name,
|
Name: o.Name,
|
||||||
|
@ -201,8 +205,8 @@ func (o *clientObject) toPersistent(
|
||||||
if o.SafeSearchConf.Enabled {
|
if o.SafeSearchConf.Enabled {
|
||||||
err = cli.SetSafeSearch(
|
err = cli.SetSafeSearch(
|
||||||
o.SafeSearchConf,
|
o.SafeSearchConf,
|
||||||
filteringConf.SafeSearchCacheSize,
|
safeSearchCacheSize,
|
||||||
time.Minute*time.Duration(filteringConf.CacheTime),
|
safeSearchCacheTTL,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("init safesearch %q: %w", cli.Name, err)
|
return nil, fmt.Errorf("init safesearch %q: %w", cli.Name, err)
|
||||||
|
|
Loading…
Reference in New Issue