Upgrade go dependencies (#25819)

This commit is contained in:
harryzcy 2023-07-13 22:00:31 -05:00 committed by GitHub
parent b81c013057
commit c5e187c389
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 379 additions and 398 deletions

File diff suppressed because one or more lines are too long

211
go.mod

File diff suppressed because it is too large Load Diff

487
go.sum

File diff suppressed because it is too large Load Diff

View File

@ -18,7 +18,7 @@ import (
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
runnerv1 "code.gitea.io/actions-proto-go/runner/v1" runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru/v2"
"github.com/nektos/act/pkg/jobparser" "github.com/nektos/act/pkg/jobparser"
"google.golang.org/protobuf/types/known/timestamppb" "google.golang.org/protobuf/types/known/timestamppb"
"xorm.io/builder" "xorm.io/builder"
@ -57,13 +57,13 @@ type ActionTask struct {
Updated timeutil.TimeStamp `xorm:"updated index"` Updated timeutil.TimeStamp `xorm:"updated index"`
} }
var successfulTokenTaskCache *lru.Cache var successfulTokenTaskCache *lru.Cache[string, any]
func init() { func init() {
db.RegisterModel(new(ActionTask), func() error { db.RegisterModel(new(ActionTask), func() error {
if setting.SuccessfulTokensCacheSize > 0 { if setting.SuccessfulTokensCacheSize > 0 {
var err error var err error
successfulTokenTaskCache, err = lru.New(setting.SuccessfulTokensCacheSize) successfulTokenTaskCache, err = lru.New[string, any](setting.SuccessfulTokensCacheSize)
if err != nil { if err != nil {
return fmt.Errorf("unable to allocate Task cache: %v", err) return fmt.Errorf("unable to allocate Task cache: %v", err)
} }

View File

@ -15,7 +15,7 @@ import (
"code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru/v2"
) )
// ErrAccessTokenNotExist represents a "AccessTokenNotExist" kind of error. // ErrAccessTokenNotExist represents a "AccessTokenNotExist" kind of error.
@ -54,7 +54,7 @@ func (err ErrAccessTokenEmpty) Unwrap() error {
return util.ErrInvalidArgument return util.ErrInvalidArgument
} }
var successfulAccessTokenCache *lru.Cache var successfulAccessTokenCache *lru.Cache[string, any]
// AccessToken represents a personal access token. // AccessToken represents a personal access token.
type AccessToken struct { type AccessToken struct {
@ -83,7 +83,7 @@ func init() {
db.RegisterModel(new(AccessToken), func() error { db.RegisterModel(new(AccessToken), func() error {
if setting.SuccessfulTokensCacheSize > 0 { if setting.SuccessfulTokensCacheSize > 0 {
var err error var err error
successfulAccessTokenCache, err = lru.New(setting.SuccessfulTokensCacheSize) successfulAccessTokenCache, err = lru.New[string, any](setting.SuccessfulTokensCacheSize)
if err != nil { if err != nil {
return fmt.Errorf("unable to allocate AccessToken cache: %w", err) return fmt.Errorf("unable to allocate AccessToken cache: %w", err)
} }
@ -154,16 +154,16 @@ func GetAccessTokenBySHA(token string) (*AccessToken, error) {
lastEight := token[len(token)-8:] lastEight := token[len(token)-8:]
if id := getAccessTokenIDFromCache(token); id > 0 { if id := getAccessTokenIDFromCache(token); id > 0 {
token := &AccessToken{ accessToken := &AccessToken{
TokenLastEight: lastEight, TokenLastEight: lastEight,
} }
// Re-get the token from the db in case it has been deleted in the intervening period // Re-get the token from the db in case it has been deleted in the intervening period
has, err := db.GetEngine(db.DefaultContext).ID(id).Get(token) has, err := db.GetEngine(db.DefaultContext).ID(id).Get(accessToken)
if err != nil { if err != nil {
return nil, err return nil, err
} }
if has { if has {
return token, nil return accessToken, nil
} }
successfulAccessTokenCache.Remove(token) successfulAccessTokenCache.Remove(token)
} }

View File

@ -11,13 +11,13 @@ import (
"code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/json"
mc "gitea.com/go-chi/cache" mc "gitea.com/go-chi/cache"
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru/v2"
) )
// TwoQueueCache represents a LRU 2Q cache adapter implementation // TwoQueueCache represents a LRU 2Q cache adapter implementation
type TwoQueueCache struct { type TwoQueueCache struct {
lock sync.Mutex lock sync.Mutex
cache *lru.TwoQueueCache cache *lru.TwoQueueCache[string, any]
interval int interval int
} }
@ -146,7 +146,7 @@ func (c *TwoQueueCache) Flush() error {
return nil return nil
} }
func (c *TwoQueueCache) checkAndInvalidate(key any) { func (c *TwoQueueCache) checkAndInvalidate(key string) {
c.lock.Lock() c.lock.Lock()
defer c.lock.Unlock() defer c.lock.Unlock()
cached, ok := c.cache.Peek(key) cached, ok := c.cache.Peek(key)
@ -155,7 +155,7 @@ func (c *TwoQueueCache) checkAndInvalidate(key any) {
} }
item, ok := cached.(*MemoryItem) item, ok := cached.(*MemoryItem)
if !ok || item.hasExpired() { if !ok || item.hasExpired() {
c.cache.Remove(item) c.cache.Remove(key)
} }
} }
@ -187,9 +187,9 @@ func (c *TwoQueueCache) StartAndGC(opts mc.Options) error {
GhostRatio: lru.Default2QGhostEntries, GhostRatio: lru.Default2QGhostEntries,
} }
_ = json.Unmarshal([]byte(opts.AdapterConfig), cfg) _ = json.Unmarshal([]byte(opts.AdapterConfig), cfg)
c.cache, err = lru.New2QParams(cfg.Size, cfg.RecentRatio, cfg.GhostRatio) c.cache, err = lru.New2QParams[string, any](cfg.Size, cfg.RecentRatio, cfg.GhostRatio)
} else { } else {
c.cache, err = lru.New2Q(size) c.cache, err = lru.New2Q[string, any](size)
} }
c.interval = opts.Interval c.interval = opts.Interval
if c.interval > 0 { if c.interval > 0 {

View File

@ -22,7 +22,7 @@ import (
"code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/util"
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru/v2"
"xorm.io/builder" "xorm.io/builder"
) )
@ -130,7 +130,7 @@ func checkEnablePushOptions(ctx context.Context, logger log.Logger, autofix bool
func checkDaemonExport(ctx context.Context, logger log.Logger, autofix bool) error { func checkDaemonExport(ctx context.Context, logger log.Logger, autofix bool) error {
numRepos := 0 numRepos := 0
numNeedUpdate := 0 numNeedUpdate := 0
cache, err := lru.New(512) cache, err := lru.New[int64, any](512)
if err != nil { if err != nil {
logger.Critical("Unable to create cache: %v", err) logger.Critical("Unable to create cache: %v", err)
return err return err

View File

@ -23,7 +23,7 @@ import (
"github.com/alecthomas/chroma/v2/formatters/html" "github.com/alecthomas/chroma/v2/formatters/html"
"github.com/alecthomas/chroma/v2/lexers" "github.com/alecthomas/chroma/v2/lexers"
"github.com/alecthomas/chroma/v2/styles" "github.com/alecthomas/chroma/v2/styles"
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru/v2"
) )
// don't index files larger than this many bytes for performance purposes // don't index files larger than this many bytes for performance purposes
@ -35,7 +35,7 @@ var (
once sync.Once once sync.Once
cache *lru.TwoQueueCache cache *lru.TwoQueueCache[string, any]
githubStyles = styles.Get("github") githubStyles = styles.Get("github")
) )
@ -46,7 +46,7 @@ func NewContext() {
highlightMapping = setting.GetHighlightMapping() highlightMapping = setting.GetHighlightMapping()
// The size 512 is simply a conservative rule of thumb // The size 512 is simply a conservative rule of thumb
c, err := lru.New2Q(512) c, err := lru.New2Q[string, any](512)
if err != nil { if err != nil {
panic(fmt.Sprintf("failed to initialize LRU cache for highlighter: %s", err)) panic(fmt.Sprintf("failed to initialize LRU cache for highlighter: %s", err))
} }

View File

@ -51,7 +51,7 @@ func (Renderer) SanitizerRules() []setting.MarkupSanitizerRule {
// Render renders orgmode rawbytes to HTML // Render renders orgmode rawbytes to HTML
func Render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error { func Render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error {
htmlWriter := org.NewHTMLWriter() htmlWriter := org.NewHTMLWriter()
htmlWriter.HighlightCodeBlock = func(source, lang string, inline bool) string { htmlWriter.HighlightCodeBlock = func(source, lang string, inline bool, params map[string]string) string {
defer func() { defer func() {
if err := recover(); err != nil { if err := recover(); err != nil {
log.Error("Panic in HighlightCodeBlock: %v\n%s", err, log.Stack(2)) log.Error("Panic in HighlightCodeBlock: %v\n%s", err, log.Stack(2))

View File

@ -8,14 +8,14 @@ import (
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru/v2"
) )
var lruCache *lru.Cache var lruCache *lru.Cache[string, any]
func init() { func init() {
var err error var err error
lruCache, err = lru.New(1000) lruCache, err = lru.New[string, any](1000)
if err != nil { if err != nil {
log.Fatal("failed to new LRU cache, err: %v", err) log.Fatal("failed to new LRU cache, err: %v", err)
} }