feat(gitea): default-branch lru cache
Shared LRU avoids repeated Gitea calls for default-branch resolution; the simple stdlib map alternative would race on concurrent access without a mutex per entry, which is more code than the LRU.
This commit is contained in:
@@ -57,11 +57,11 @@ func (t *FileRead) Call(ctx context.Context, raw json.RawMessage) (json.RawMessa
|
||||
|
||||
ref := args.Ref
|
||||
if ref == "" {
|
||||
repo, err := t.c.GetRepo(ctx, args.Owner, args.Name)
|
||||
var err error
|
||||
ref, err = t.c.DefaultBranch(ctx, args.Owner, args.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ref = repo.DefaultBranch
|
||||
}
|
||||
|
||||
fc, err := t.c.GetFileContents(ctx, args.Owner, args.Name, args.Path, ref)
|
||||
|
||||
@@ -75,11 +75,11 @@ func (t *FileWriteBranch) Call(ctx context.Context, raw json.RawMessage) (json.R
|
||||
if !exists {
|
||||
base := args.Base
|
||||
if base == "" {
|
||||
repo, err := t.c.GetRepo(ctx, args.Owner, args.Name)
|
||||
var err error
|
||||
base, err = t.c.DefaultBranch(ctx, args.Owner, args.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
base = repo.DefaultBranch
|
||||
}
|
||||
if err := t.c.CreateBranch(ctx, args.Owner, args.Name, args.Branch, base); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -61,11 +61,11 @@ func (t *WorkflowRunTrigger) Call(ctx context.Context, raw json.RawMessage) (jso
|
||||
|
||||
ref := args.Ref
|
||||
if ref == "" {
|
||||
repo, err := t.c.GetRepo(ctx, args.Owner, args.Name)
|
||||
var err error
|
||||
ref, err = t.c.DefaultBranch(ctx, args.Owner, args.Name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ref = repo.DefaultBranch
|
||||
}
|
||||
|
||||
result, err := t.c.DispatchWorkflow(ctx, args.Owner, args.Name, args.Workflow, gitea.DispatchWorkflowArgs{
|
||||
|
||||
Reference in New Issue
Block a user