From 0073b3a9b28cf97b6857f5d952adb1931c3222ae Mon Sep 17 00:00:00 2001 From: d4x1 <1507509064@qq.com> Date: Wed, 18 Dec 2024 15:42:16 +0800 Subject: [PATCH] fix(zentao): remove UnCacheableConnetion interface, try to fix it with another way --- backend/core/plugin/plugin_datasource.go | 5 ----- .../helpers/pluginhelper/api/ds_remote_api_proxy_api.go | 8 ++------ backend/plugins/zentao/models/connection.go | 8 ++++---- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/backend/core/plugin/plugin_datasource.go b/backend/core/plugin/plugin_datasource.go index 4d438dabb53..d40bfc98008 100644 --- a/backend/core/plugin/plugin_datasource.go +++ b/backend/core/plugin/plugin_datasource.go @@ -41,11 +41,6 @@ type CacheableConnection interface { GetHash() string } -type UnCacheableConnection interface { - ApiConnection - UncCacheable() bool -} - // ApiAuthenticator is to be implemented by a Concreate Connection if Authorization is required type ApiAuthenticator interface { // SetupAuthentication is a hook function for connection to set up authentication for the HTTP request diff --git a/backend/helpers/pluginhelper/api/ds_remote_api_proxy_api.go b/backend/helpers/pluginhelper/api/ds_remote_api_proxy_api.go index cdbb29c90fd..b0c4b0439c2 100644 --- a/backend/helpers/pluginhelper/api/ds_remote_api_proxy_api.go +++ b/backend/helpers/pluginhelper/api/ds_remote_api_proxy_api.go @@ -63,15 +63,11 @@ func (rap *DsRemoteApiProxyHelper[C]) prepare(input *plugin.ApiResourceInput) (* func (rap *DsRemoteApiProxyHelper[C]) getApiClient(connection *C) (*ApiClient, errors.Error) { c := interface{}(connection) key := "" - var cacheable = false - if unCacheableConnection, ok := c.(plugin.UnCacheableConnection); ok { - cacheable = !unCacheableConnection.UncCacheable() - } if cacheableConn, ok := c.(plugin.CacheableConnection); ok { key = cacheableConn.GetHash() } // try to reuse api client - if key != "" && cacheable { + if key != "" { rap.httpClientCacheMutex.RLock() client, ok := rap.httpClientCache[key] rap.httpClientCacheMutex.RUnlock() @@ -86,7 +82,7 @@ func (rap *DsRemoteApiProxyHelper[C]) getApiClient(connection *C) (*ApiClient, e return nil, err } // cache the client if key is not empty - if key != "" && cacheable { + if key != "" { rap.httpClientCacheMutex.Lock() rap.httpClientCache[key] = client rap.httpClientCacheMutex.Unlock() diff --git a/backend/plugins/zentao/models/connection.go b/backend/plugins/zentao/models/connection.go index 385d4e5a511..949dd36d2b4 100644 --- a/backend/plugins/zentao/models/connection.go +++ b/backend/plugins/zentao/models/connection.go @@ -73,9 +73,9 @@ type ZentaoConn struct { DbMaxConns int `json:"dbMaxConns" mapstructure:"dbMaxConns"` } -func (connection ZentaoConn) UncCacheable() bool { +func (connection ZentaoConn) GetHash() string { // zentao's token will expire after about 24min, so api client cannot be cached. - return true + return "" } func (connection ZentaoConn) Sanitize() ZentaoConn { @@ -111,8 +111,8 @@ func (connection ZentaoConn) SanitizeDbUrl() string { return dbUrl } -func (connection ZentaoConnection) UncCacheable() bool { - return connection.ZentaoConn.UncCacheable() +func (connection ZentaoConnection) GetHash() string { + return connection.ZentaoConn.GetHash() } func (connection ZentaoConnection) Sanitize() ZentaoConnection {