This is an automated email from the ASF dual-hosted git repository.
lynwee pushed a commit to branch fix-1218-2
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/fix-1218-2 by this push:
new 308a3e6b3 fix(zentao): make sure connection uncacheable
308a3e6b3 is described below
commit 308a3e6b343f2652526e03530c5c0a42b8b580c2
Author: d4x1 <[email protected]>
AuthorDate: Wed Dec 18 14:43:49 2024 +0800
fix(zentao): make sure connection uncacheable
---
backend/core/plugin/plugin_datasource.go | 5 +++++
backend/helpers/pluginhelper/api/ds_remote_api_proxy_api.go | 8 ++++++--
backend/plugins/zentao/models/connection.go | 9 +++++++++
3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/backend/core/plugin/plugin_datasource.go
b/backend/core/plugin/plugin_datasource.go
index d40bfc980..4d438dabb 100644
--- a/backend/core/plugin/plugin_datasource.go
+++ b/backend/core/plugin/plugin_datasource.go
@@ -41,6 +41,11 @@ 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 9ea8b5d2a..6c757ba9f 100644
--- a/backend/helpers/pluginhelper/api/ds_remote_api_proxy_api.go
+++ b/backend/helpers/pluginhelper/api/ds_remote_api_proxy_api.go
@@ -67,11 +67,15 @@ func (rap *DsRemoteApiProxyHelper[C]) prepare(input
*plugin.ApiResourceInput) (*
func (rap *DsRemoteApiProxyHelper[C]) getApiClient(connection *C) (*ApiClient,
errors.Error) {
c := interface{}(connection)
key := ""
+ var cacheable bool = 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 != "" {
+ if key != "" && cacheable {
rap.httpClientCacheMutex.RLock()
client, ok := rap.httpClientCache[key]
rap.httpClientCacheMutex.RUnlock()
@@ -86,7 +90,7 @@ func (rap *DsRemoteApiProxyHelper[C]) getApiClient(connection
*C) (*ApiClient, e
return nil, err
}
// cache the client if key is not empty
- if key != "" {
+ if key != "" && cacheable {
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 0554450e7..385d4e5a5 100644
--- a/backend/plugins/zentao/models/connection.go
+++ b/backend/plugins/zentao/models/connection.go
@@ -73,6 +73,11 @@ type ZentaoConn struct {
DbMaxConns int `json:"dbMaxConns" mapstructure:"dbMaxConns"`
}
+func (connection ZentaoConn) UncCacheable() bool {
+ // zentao's token will expire after about 24min, so api client cannot
be cached.
+ return true
+}
+
func (connection ZentaoConn) Sanitize() ZentaoConn {
connection.Password = ""
if connection.DbUrl != "" {
@@ -106,6 +111,10 @@ func (connection ZentaoConn) SanitizeDbUrl() string {
return dbUrl
}
+func (connection ZentaoConnection) UncCacheable() bool {
+ return connection.ZentaoConn.UncCacheable()
+}
+
func (connection ZentaoConnection) Sanitize() ZentaoConnection {
connection.ZentaoConn = connection.ZentaoConn.Sanitize()
return connection