Code optimization

This commit is contained in:
Alexander Sheiko 2021-01-28 11:12:20 +02:00
parent a4375c3b2d
commit 6c4a1cc054
4 changed files with 28 additions and 42 deletions

View file

@ -94,3 +94,20 @@ func (s *Scraper) GetProfile(username string) (Profile, error) {
func GetProfile(username string) (Profile, error) {
return defaultScraper.GetProfile(username)
}
// GetUserIDByScreenName from API
func (s *Scraper) GetUserIDByScreenName(screenName string) (string, error) {
id, ok := cacheIDs.Load(screenName)
if ok {
return id.(string), nil
}
profile, err := s.GetProfile(screenName)
if err != nil {
return "", err
}
cacheIDs.Store(screenName, profile.UserID)
return profile.UserID, nil
}