1
0
mirror of https://github.com/astaxie/beego.git synced 2024-07-04 14:25:12 +00:00

Merge pull request #4261 from flycash/reduceCache

make stmt cache smaller
This commit is contained in:
Ming Deng 2020-10-10 22:10:43 +08:00 committed by GitHub
commit db3defa76a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 89 additions and 75 deletions

View File

@ -38,8 +38,9 @@ import (
"github.com/gomodule/redigo/redis" "github.com/gomodule/redigo/redis"
"github.com/astaxie/beego/cache"
"strings" "strings"
"github.com/astaxie/beego/cache"
) )
var ( var (

View File

@ -1,8 +1,10 @@
package param package param
import "testing" import (
import "reflect" "reflect"
import "time" "testing"
"time"
)
type testDefinition struct { type testDefinition struct {
strValue string strValue string

View File

@ -19,9 +19,10 @@ import (
"strconv" "strconv"
"testing" "testing"
"github.com/astaxie/beego/context"
"os" "os"
"path/filepath" "path/filepath"
"github.com/astaxie/beego/context"
) )
func TestGetInt(t *testing.T) { func TestGetInt(t *testing.T) {

View File

@ -16,9 +16,9 @@ package logs
import ( import (
"bytes" "bytes"
"strings"
"encoding/json" "encoding/json"
"fmt" "fmt"
"strings"
"time" "time"
) )

View File

@ -18,10 +18,11 @@ import (
"context" "context"
"database/sql" "database/sql"
"fmt" "fmt"
lru "github.com/hashicorp/golang-lru"
"reflect" "reflect"
"sync" "sync"
"time" "time"
lru "github.com/hashicorp/golang-lru"
) )
// DriverType database driver constant int. // DriverType database driver constant int.
@ -459,7 +460,9 @@ func newStmtDecorator(sqlStmt *sql.Stmt) *stmtDecorator {
} }
func newStmtDecoratorLruWithEvict() *lru.Cache { func newStmtDecoratorLruWithEvict() *lru.Cache {
cache, _ := lru.NewWithEvict(1000, func(key interface{}, value interface{}) { // temporarily solution
// we fixed this problem in v2.x
cache, _ := lru.NewWithEvict(50, func(key interface{}, value interface{}) {
value.(*stmtDecorator).destroy() value.(*stmtDecorator).destroy()
}) })
return cache return cache

View File

@ -40,10 +40,11 @@
package authz package authz
import ( import (
"net/http"
"github.com/astaxie/beego" "github.com/astaxie/beego"
"github.com/astaxie/beego/context" "github.com/astaxie/beego/context"
"github.com/casbin/casbin" "github.com/casbin/casbin"
"net/http"
) )
// NewAuthorizer returns the authorizer. // NewAuthorizer returns the authorizer.

View File

@ -15,13 +15,14 @@
package authz package authz
import ( import (
"net/http"
"net/http/httptest"
"testing"
"github.com/astaxie/beego" "github.com/astaxie/beego"
"github.com/astaxie/beego/context" "github.com/astaxie/beego/context"
"github.com/astaxie/beego/plugins/auth" "github.com/astaxie/beego/plugins/auth"
"github.com/casbin/casbin" "github.com/casbin/casbin"
"net/http"
"net/http/httptest"
"testing"
) )
func testRequest(t *testing.T, handler *beego.ControllerRegister, user string, path string, method string, code int) { func testRequest(t *testing.T, handler *beego.ControllerRegister, user string, path string, method string, code int) {

View File

@ -31,14 +31,16 @@
// //
// more docs: http://beego.me/docs/module/session.md // more docs: http://beego.me/docs/module/session.md
package redis_cluster package redis_cluster
import ( import (
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"time"
"github.com/astaxie/beego/session" "github.com/astaxie/beego/session"
rediss "github.com/go-redis/redis" rediss "github.com/go-redis/redis"
"time"
) )
var redispder = &Provider{} var redispder = &Provider{}

View File

@ -33,13 +33,14 @@
package redis_sentinel package redis_sentinel
import ( import (
"github.com/astaxie/beego/session"
"github.com/go-redis/redis"
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"time" "time"
"github.com/astaxie/beego/session"
"github.com/go-redis/redis"
) )
var redispder = &Provider{} var redispder = &Provider{}

View File

@ -369,7 +369,6 @@ func TestFileSessionStore_SessionRelease(t *testing.T) {
t.Error(err) t.Error(err)
} }
s.Set(i, i) s.Set(i, i)
s.SessionRelease(nil) s.SessionRelease(nil)
} }

View File

@ -16,12 +16,13 @@ package beego
import ( import (
"bytes" "bytes"
"github.com/astaxie/beego/testdata"
"github.com/elazarl/go-bindata-assetfs"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
"testing" "testing"
"github.com/astaxie/beego/testdata"
"github.com/elazarl/go-bindata-assetfs"
) )
var header = `{{define "header"}} var header = `{{define "header"}}

3
testdata/bindata.go vendored
View File

@ -11,13 +11,14 @@ import (
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"fmt" "fmt"
"github.com/elazarl/go-bindata-assetfs"
"io" "io"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"time" "time"
"github.com/elazarl/go-bindata-assetfs"
) )
func bindataRead(data []byte, name string) ([]byte, error) { func bindataRead(data []byte, name string) ([]byte, error) {

View File

@ -16,13 +16,14 @@ package validation
import ( import (
"fmt" "fmt"
"github.com/astaxie/beego/logs"
"reflect" "reflect"
"regexp" "regexp"
"strings" "strings"
"sync" "sync"
"time" "time"
"unicode/utf8" "unicode/utf8"
"github.com/astaxie/beego/logs"
) )
// CanSkipFuncs will skip valid if RequiredFirst is true and the struct field's value is empty // CanSkipFuncs will skip valid if RequiredFirst is true and the struct field's value is empty