Skip to content

Commit 8b5b26c

Browse files
fix (plg_backend_psql): caching issue
1 parent d1b993a commit 8b5b26c

File tree

4 files changed

+7
-17
lines changed

4 files changed

+7
-17
lines changed

server/plugin/plg_backend_psql/index.go

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,16 @@ import (
1111
_ "github.com/lib/pq"
1212
)
1313

14-
var PGCache AppCache
15-
1614
type PSQL struct {
1715
db *sql.DB
1816
ctx context.Context
1917
}
2018

2119
func init() {
2220
Backend.Register("psql", PSQL{})
23-
24-
PGCache = NewAppCache(2, 1)
25-
PGCache.OnEvict(func(key string, value interface{}) {
26-
c := value.(*PSQL)
27-
c.Close()
28-
})
2921
}
3022

3123
func (this PSQL) Init(params map[string]string, app *App) (IBackend, error) {
32-
if d := PGCache.Get(params); d != nil {
33-
backend := d.(*PSQL)
34-
if backend.db.Ping() == nil {
35-
backend.ctx = app.Context
36-
return backend, nil
37-
}
38-
PGCache.Del(params)
39-
}
4024
host := params["host"]
4125
port := withDefault(params["port"], "5432")
4226
user := params["user"]
@@ -64,7 +48,6 @@ func (this PSQL) Init(params map[string]string, app *App) (IBackend, error) {
6448
db: db,
6549
ctx: app.Context,
6650
}
67-
PGCache.Set(params, backend)
6851
return backend, nil
6952
}
7053

@@ -118,21 +101,25 @@ func (this PSQL) LoginForm() Form {
118101
}
119102

120103
func (this PSQL) Touch(path string) error {
104+
defer this.Close()
121105
if !strings.HasSuffix(path, ".form") {
122106
return ErrNotValid
123107
}
124108
return nil
125109
}
126110

127111
func (this PSQL) Rm(path string) error {
112+
defer this.Close()
128113
return ErrNotAuthorized
129114
}
130115

131116
func (this PSQL) Mkdir(path string) error {
117+
defer this.Close()
132118
return ErrNotValid
133119
}
134120

135121
func (this PSQL) Mv(from string, to string) error {
122+
defer this.Close()
136123
return ErrNotValid
137124
}
138125

server/plugin/plg_backend_psql/index_cat.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
)
1212

1313
func (this PSQL) Cat(path string) (io.ReadCloser, error) {
14+
defer this.Close()
1415
l, err := getPath(path)
1516
if err != nil {
1617
return nil, err

server/plugin/plg_backend_psql/index_ls.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
)
88

99
func (this PSQL) Ls(path string) ([]os.FileInfo, error) {
10+
defer this.Close()
1011
l, err := getPath(path)
1112
if err != nil {
1213
Log.Debug("pl_backend_psql::ls method=getPath err=%s", err.Error())

server/plugin/plg_backend_psql/index_save.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
)
1414

1515
func (this PSQL) Save(path string, file io.Reader) error {
16+
defer this.Close()
1617
l, err := getPath(path)
1718
if err != nil {
1819
return err

0 commit comments

Comments
 (0)