(pds string, token string, items []string, ignoreCache bool)
| 500 | } |
| 501 | |
| 502 | func GetUsersInfo(pds string, token string, items []string, ignoreCache bool) ([]*bridge.TwitterUser, error) { |
| 503 | var results []*bridge.TwitterUser |
| 504 | var missing []string |
| 505 | |
| 506 | if !ignoreCache { |
| 507 | for _, screen_name := range items { |
| 508 | if user, found := userCache.Get(screen_name); found { |
| 509 | results = append(results, &user) |
| 510 | } else { |
| 511 | missing = append(missing, screen_name) |
| 512 | } |
| 513 | } |
| 514 | |
| 515 | if len(missing) == 0 { |
| 516 | return results, nil |
| 517 | } |
| 518 | } else { |
| 519 | missing = items |
| 520 | } |
| 521 | |
| 522 | // Parallel fetching for chunks of up to 25 at a time |
| 523 | var wg sync.WaitGroup |
| 524 | var mu sync.Mutex |
| 525 | for i := 0; i < len(missing); i += 25 { |
| 526 | end := i + 25 |
| 527 | if end > len(missing) { |
| 528 | end = len(missing) |
| 529 | } |
| 530 | chunk := missing[i:end] |
| 531 | |
| 532 | wg.Add(1) |
| 533 | go func(c []string) { |
| 534 | defer wg.Done() |
| 535 | |
| 536 | url := pds + "/xrpc/app.bsky.actor.getProfiles" + "?actors=" + strings.Join(c, "&actors=") |
| 537 | resp, err := SendRequest(&token, http.MethodGet, url, nil) |
| 538 | if err != nil { |
| 539 | fmt.Println(err) |
| 540 | return |
| 541 | } |
| 542 | defer resp.Body.Close() |
| 543 | if resp.StatusCode != http.StatusOK { |
| 544 | bodyBytes, _ := io.ReadAll(resp.Body) |
| 545 | fmt.Println("Response Status:", resp.StatusCode) |
| 546 | fmt.Println("Response Body:", string(bodyBytes)) |
| 547 | return |
| 548 | } |
| 549 | |
| 550 | var authors struct { |
| 551 | Profiles []User `json:"profiles"` |
| 552 | } |
| 553 | if err := json.NewDecoder(resp.Body).Decode(&authors); err != nil { |
| 554 | return |
| 555 | } |
| 556 | |
| 557 | mu.Lock() |
| 558 | for _, author := range authors.Profiles { |
| 559 | userObj := AuthorTTB(author) |
no test coverage detected