Monorepo for Tangled tangled.org

impl async resolver for multiple idents

Changed files
+53 -16
appview
pages
templates
state
knotserver
git
types
+1 -1
appview/pages/pages.go
··· 366 366 func (p *Pages) RepoBlob(w io.Writer, params RepoBlobParams) error { 367 367 if params.Lines < 5000 { 368 368 c := params.Contents 369 - style := styles.Get("xcode") 369 + style := styles.Get("bw") 370 370 formatter := chromahtml.New( 371 371 chromahtml.InlineCode(true), 372 372 chromahtml.WithLineNumbers(true),
+1 -1
appview/pages/templates/repo/blob.html
··· 22 22 {{ end }} 23 23 {{ end }} 24 24 </div> 25 - <div id="file-info"> 25 + <div id="file-info" class="text-gray-500 text-xs"> 26 26 {{ .Lines }} lines 27 27 <span class="select-none px-2 [&:before]:content-['·']"></span> 28 28 {{ byteFmt .SizeHint }}
+1 -1
appview/pages/templates/repo/commit.html
··· 108 108 {{ else }} 109 109 <pre class="overflow-auto"> 110 110 {{- range .TextFragments -}} 111 - <div class="bg-gray-100 text-gray-500 select-none">{{ .Comment }}</div> 111 + <div class="bg-gray-100 text-gray-500 select-none">{{ .Header }}</div> 112 112 113 113 {{- range .Lines -}} 114 114 {{- if eq .Op.String "+" -}}
+32
appview/resolver.go
··· 2 2 3 3 import ( 4 4 "context" 5 + "sync" 5 6 6 7 "github.com/bluesky-social/indigo/atproto/identity" 7 8 "github.com/bluesky-social/indigo/atproto/syntax" ··· 25 26 26 27 return r.directory.Lookup(ctx, *id) 27 28 } 29 + 30 + func (r *Resolver) ResolveIdents(ctx context.Context, idents []string) []*identity.Identity { 31 + results := make([]*identity.Identity, len(idents)) 32 + var wg sync.WaitGroup 33 + 34 + // Create a channel to handle context cancellation 35 + done := make(chan struct{}) 36 + defer close(done) 37 + 38 + // Start a goroutine for each identifier 39 + for idx, ident := range idents { 40 + wg.Add(1) 41 + go func(index int, id string) { 42 + defer wg.Done() 43 + 44 + select { 45 + case <-ctx.Done(): 46 + results[index] = nil 47 + case <-done: 48 + results[index] = nil 49 + default: 50 + // Resolve the identifier - if error, identity will be nil 51 + identity, _ := r.ResolveIdent(ctx, id) 52 + results[index] = identity 53 + } 54 + }(idx, ident) 55 + } 56 + 57 + wg.Wait() 58 + return results 59 + }
+14 -9
appview/state/repo.go
··· 480 480 481 481 did := item[0] 482 482 483 - var handle string 484 - id, err := s.resolver.ResolveIdent(ctx, did) 485 - if err != nil { 486 - handle = "" 487 - } else { 488 - handle = string(id.Handle) 489 - } 490 - 491 483 c := pages.Collaborator{ 492 484 Did: did, 493 - Handle: handle, 485 + Handle: "", 494 486 Role: role, 495 487 } 496 488 collaborators = append(collaborators, c) 489 + } 490 + 491 + // populate all collborators with handles 492 + identsToResolve := make([]string, len(collaborators)) 493 + for i, collab := range collaborators { 494 + identsToResolve[i] = collab.Did 495 + } 496 + 497 + resolvedIdents := s.resolver.ResolveIdents(ctx, identsToResolve) 498 + for i, resolved := range resolvedIdents { 499 + if resolved != nil { 500 + collaborators[i].Handle = resolved.Handle.String() 501 + } 497 502 } 498 503 499 504 return collaborators, nil
+2 -2
knotserver/git/diff.go
··· 66 66 67 67 for _, tf := range d.TextFragments { 68 68 ndiff.TextFragments = append(ndiff.TextFragments, types.TextFragment{ 69 - Comment: tf.Comment, 70 - Lines: tf.Lines, 69 + Header: tf.Header(), 70 + Lines: tf.Lines, 71 71 }) 72 72 for _, l := range tf.Lines { 73 73 switch l.Op {
+2 -2
types/diff.go
··· 6 6 ) 7 7 8 8 type TextFragment struct { 9 - Comment string `json:"comment"` 10 - Lines []gitdiff.Line `json:"lines"` 9 + Header string `json:"comment"` 10 + Lines []gitdiff.Line `json:"lines"` 11 11 } 12 12 13 13 type Diff struct {