Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade go dependencies #25819

Merged
merged 20 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
lunny marked this conversation as resolved.
Show resolved Hide resolved
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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think key should be used when removing from cache.

}
}

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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function is changed in niklasfasching/go-org@9b56fc9

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
Loading