[mirror] Scalable static site server for Git forges (like GitHub Pages)

Update `-audit-log` to fetch records in parallel.

This makes it *much* faster.

+20 -4
+20 -4
src/main.go
··· 421 logc.Fatalln(ctx, err) 422 } 423 424 for id, err := range backend.SearchAuditLog(ctx, SearchAuditLogOptions{}) { 425 if err != nil { 426 logc.Fatalln(ctx, err) 427 } 428 - record, err := backend.QueryAuditLog(ctx, id) 429 - if err != nil { 430 - logc.Fatalln(ctx, err) 431 - } 432 fmt.Fprintf(color.Output, "%s %s %s %s %s\n", 433 record.GetAuditID().String(), 434 color.HiWhiteString(record.GetTimestamp().AsTime().UTC().Format(time.RFC3339)),
··· 421 logc.Fatalln(ctx, err) 422 } 423 424 + ch := make(chan *AuditRecord) 425 + ids := []AuditID{} 426 for id, err := range backend.SearchAuditLog(ctx, SearchAuditLogOptions{}) { 427 if err != nil { 428 logc.Fatalln(ctx, err) 429 } 430 + go func() { 431 + if record, err := backend.QueryAuditLog(ctx, id); err != nil { 432 + logc.Fatalln(ctx, err) 433 + } else { 434 + ch <- record 435 + } 436 + }() 437 + ids = append(ids, id) 438 + } 439 + 440 + records := map[AuditID]*AuditRecord{} 441 + for len(records) < len(ids) { 442 + record := <-ch 443 + records[record.GetAuditID()] = record 444 + } 445 + 446 + for _, id := range ids { 447 + record := records[id] 448 fmt.Fprintf(color.Output, "%s %s %s %s %s\n", 449 record.GetAuditID().String(), 450 color.HiWhiteString(record.GetTimestamp().AsTime().UTC().Format(time.RFC3339)),