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

View file

@ -11,13 +11,13 @@ import (
"code.gitea.io/gitea/modules/json"
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
type TwoQueueCache struct {
lock sync.Mutex
cache *lru.TwoQueueCache
cache *lru.TwoQueueCache[string, any]
interval int
}
@ -146,7 +146,7 @@ func (c *TwoQueueCache) Flush() error {
return nil
}
func (c *TwoQueueCache) checkAndInvalidate(key any) {
func (c *TwoQueueCache) checkAndInvalidate(key string) {
c.lock.Lock()
defer c.lock.Unlock()
cached, ok := c.cache.Peek(key)
@ -155,7 +155,7 @@ func (c *TwoQueueCache) checkAndInvalidate(key any) {
}
item, ok := cached.(*MemoryItem)
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,
}
_ = 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 {
c.cache, err = lru.New2Q(size)
c.cache, err = lru.New2Q[string, any](size)
}
c.interval = opts.Interval
if c.interval > 0 {

View file

@ -22,7 +22,7 @@ import (
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
lru "github.com/hashicorp/golang-lru"
lru "github.com/hashicorp/golang-lru/v2"
"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 {
numRepos := 0
numNeedUpdate := 0
cache, err := lru.New(512)
cache, err := lru.New[int64, any](512)
if err != nil {
logger.Critical("Unable to create cache: %v", err)
return err

View file

@ -23,7 +23,7 @@ import (
"github.com/alecthomas/chroma/v2/formatters/html"
"github.com/alecthomas/chroma/v2/lexers"
"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
@ -35,7 +35,7 @@ var (
once sync.Once
cache *lru.TwoQueueCache
cache *lru.TwoQueueCache[string, any]
githubStyles = styles.Get("github")
)
@ -46,7 +46,7 @@ func NewContext() {
highlightMapping = setting.GetHighlightMapping()
// 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 {
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
func Render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error {
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() {
if err := recover(); err != nil {
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"
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() {
var err error
lruCache, err = lru.New(1000)
lruCache, err = lru.New[string, any](1000)
if err != nil {
log.Fatal("failed to new LRU cache, err: %v", err)
}