Skip to content

Commit

Permalink
Upgrade go dependencies (#25819)
Browse files Browse the repository at this point in the history
  • Loading branch information
harryzcy authored Jul 14, 2023
1 parent b81c013 commit c5e187c
Show file tree
Hide file tree
Showing 10 changed files with 379 additions and 398 deletions.
31 changes: 23 additions & 8 deletions assets/go-licenses.json

Large diffs are not rendered by default.

211 changes: 106 additions & 105 deletions go.mod

Large diffs are not rendered by default.

487 changes: 226 additions & 261 deletions go.sum

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions models/actions/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"code.gitea.io/gitea/modules/util"

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"
"google.golang.org/protobuf/types/known/timestamppb"
"xorm.io/builder"
Expand Down Expand Up @@ -57,13 +57,13 @@ type ActionTask struct {
Updated timeutil.TimeStamp `xorm:"updated index"`
}

var successfulTokenTaskCache *lru.Cache
var successfulTokenTaskCache *lru.Cache[string, any]

func init() {
db.RegisterModel(new(ActionTask), func() error {
if setting.SuccessfulTokensCacheSize > 0 {
var err error
successfulTokenTaskCache, err = lru.New(setting.SuccessfulTokensCacheSize)
successfulTokenTaskCache, err = lru.New[string, any](setting.SuccessfulTokensCacheSize)
if err != nil {
return fmt.Errorf("unable to allocate Task cache: %v", err)
}
Expand Down
12 changes: 6 additions & 6 deletions models/auth/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"code.gitea.io/gitea/modules/timeutil"
"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.
Expand Down Expand Up @@ -54,7 +54,7 @@ func (err ErrAccessTokenEmpty) Unwrap() error {
return util.ErrInvalidArgument
}

var successfulAccessTokenCache *lru.Cache
var successfulAccessTokenCache *lru.Cache[string, any]

// AccessToken represents a personal access token.
type AccessToken struct {
Expand Down Expand Up @@ -83,7 +83,7 @@ func init() {
db.RegisterModel(new(AccessToken), func() error {
if setting.SuccessfulTokensCacheSize > 0 {
var err error
successfulAccessTokenCache, err = lru.New(setting.SuccessfulTokensCacheSize)
successfulAccessTokenCache, err = lru.New[string, any](setting.SuccessfulTokensCacheSize)
if err != nil {
return fmt.Errorf("unable to allocate AccessToken cache: %w", err)
}
Expand Down Expand Up @@ -154,16 +154,16 @@ func GetAccessTokenBySHA(token string) (*AccessToken, error) {
lastEight := token[len(token)-8:]

if id := getAccessTokenIDFromCache(token); id > 0 {
token := &AccessToken{
accessToken := &AccessToken{
TokenLastEight: lastEight,
}
// 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 {
return nil, err
}
if has {
return token, nil
return accessToken, nil
}
successfulAccessTokenCache.Remove(token)
}
Expand Down
12 changes: 6 additions & 6 deletions modules/cache/cache_twoqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions modules/doctor/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions modules/highlight/highlight.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,7 +35,7 @@ var (

once sync.Once

cache *lru.TwoQueueCache
cache *lru.TwoQueueCache[string, any]

githubStyles = styles.Get("github")
)
Expand All @@ -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))
}
Expand Down
2 changes: 1 addition & 1 deletion modules/markup/orgmode/orgmode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions modules/regexplru/regexplru.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit c5e187c

Please sign in to comment.