Skip to content

Commit

Permalink
fix(zentao): remove UnCacheableConnetion interface, try to fix it wit…
Browse files Browse the repository at this point in the history
…h another way
  • Loading branch information
d4x1 committed Dec 18, 2024
1 parent 13cc09f commit 0073b3a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
5 changes: 0 additions & 5 deletions backend/core/plugin/plugin_datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 2 additions & 6 deletions backend/helpers/pluginhelper/api/ds_remote_api_proxy_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions backend/plugins/zentao/models/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0073b3a

Please sign in to comment.