modified internal/feed/discover.go +11 -0
| @@ -7,6 +7,7 @@ import ( |
| 7 | 7 | "net/url" |
| 8 | 8 | "regexp" |
| 9 | 9 | "strings" |
| 10 | + "sync" |
| 10 | 11 | "time" |
| 11 | 12 | |
| 12 | 13 | "pkg.rbrt.fr/glean/internal/httpclient" |
| @@ -117,8 +118,11 @@ func findFavicon(ctx context.Context, base *url.URL, links []string) string { |
| 117 | 118 | ctx, cancel := context.WithCancel(ctx) |
| 118 | 119 | defer cancel() |
| 119 | 120 | |
| 121 | + var wg sync.WaitGroup |
| 120 | 122 | for _, path := range faviconPaths { |
| 123 | + wg.Add(1) |
| 121 | 124 | go func(path string) { |
| 125 | + defer wg.Done() |
| 122 | 126 | u, _ := url.Parse(path) |
| 123 | 127 | resolved := origin.ResolveReference(u) |
| 124 | 128 | req, err := http.NewRequestWithContext(ctx, http.MethodGet, resolved.String(), nil) |
| @@ -140,11 +144,18 @@ func findFavicon(ctx context.Context, base *url.URL, links []string) string { |
| 140 | 144 | }(path) |
| 141 | 145 | } |
| 142 | 146 | |
| 147 | + done := make(chan struct{}) |
| 148 | + go func() { |
| 149 | + wg.Wait() |
| 150 | + close(done) |
| 151 | + }() |
| 152 | + |
| 143 | 153 | select { |
| 144 | 154 | case r := <-found: |
| 145 | 155 | if r.found { |
| 146 | 156 | return r.url |
| 147 | 157 | } |
| 158 | + case <-done: |
| 148 | 159 | case <-ctx.Done(): |
| 149 | 160 | } |
| 150 | 161 | return "" |
| @@ -7,6 +7,7 @@ import ( |
| 7 | "net/url" | 7 | "net/url" |
| 8 | "regexp" | 8 | "regexp" |
| 9 | "strings" | 9 | "strings" |
| | 10 | + "sync" |
| 10 | "time" | 11 | "time" |
| 11 | | 12 | |
| 12 | "pkg.rbrt.fr/glean/internal/httpclient" | 13 | "pkg.rbrt.fr/glean/internal/httpclient" |
| @@ -117,8 +118,11 @@ func findFavicon(ctx context.Context, base *url.URL, links []string) string { |
| 117 | ctx, cancel := context.WithCancel(ctx) | 118 | ctx, cancel := context.WithCancel(ctx) |
| 118 | defer cancel() | 119 | defer cancel() |
| 119 | | 120 | |
| | 121 | + var wg sync.WaitGroup |
| 120 | for _, path := range faviconPaths { | 122 | for _, path := range faviconPaths { |
| | 123 | + wg.Add(1) |
| 121 | go func(path string) { | 124 | go func(path string) { |
| | 125 | + defer wg.Done() |
| 122 | u, _ := url.Parse(path) | 126 | u, _ := url.Parse(path) |
| 123 | resolved := origin.ResolveReference(u) | 127 | resolved := origin.ResolveReference(u) |
| 124 | req, err := http.NewRequestWithContext(ctx, http.MethodGet, resolved.String(), nil) | 128 | req, err := http.NewRequestWithContext(ctx, http.MethodGet, resolved.String(), nil) |
| @@ -140,11 +144,18 @@ func findFavicon(ctx context.Context, base *url.URL, links []string) string { |
| 140 | }(path) | 144 | }(path) |
| 141 | } | 145 | } |
| 142 | | 146 | |
| | 147 | + done := make(chan struct{}) |
| | 148 | + go func() { |
| | 149 | + wg.Wait() |
| | 150 | + close(done) |
| | 151 | + }() |
| | 152 | + |
| 143 | select { | 153 | select { |
| 144 | case r := <-found: | 154 | case r := <-found: |
| 145 | if r.found { | 155 | if r.found { |
| 146 | return r.url | 156 | return r.url |
| 147 | } | 157 | } |
| | 158 | + case <-done: |
| 148 | case <-ctx.Done(): | 159 | case <-ctx.Done(): |
| 149 | } | 160 | } |
| 150 | return "" | 161 | return "" |
modified internal/feed/fetcher.go +1 -1
| @@ -209,7 +209,7 @@ func (s *Scheduler) FetchFeed(ctx context.Context, feed *Feed) { |
| 209 | 209 | |
| 210 | 210 | faviconURL := result.Feed.FaviconURL |
| 211 | 211 | if faviconURL == "" && feed.FaviconURL == "" { |
| 212 | | - faviconURL = ResolveFavicon(context.Background(), feed.URL, feed.SiteURL) |
| 212 | + faviconURL = ResolveFavicon(ctx, feed.URL, feed.SiteURL) |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | if err := s.store.StoreFetchResult(ctx, feed.URL, result.Articles, faviconURL); err != nil { |
| @@ -209,7 +209,7 @@ func (s *Scheduler) FetchFeed(ctx context.Context, feed *Feed) { |
| 209 | | 209 | |
| 210 | faviconURL := result.Feed.FaviconURL | 210 | faviconURL := result.Feed.FaviconURL |
| 211 | if faviconURL == "" && feed.FaviconURL == "" { | 211 | if faviconURL == "" && feed.FaviconURL == "" { |
| 212 | - faviconURL = ResolveFavicon(context.Background(), feed.URL, feed.SiteURL) | 212 | + faviconURL = ResolveFavicon(ctx, feed.URL, feed.SiteURL) |
| 213 | } | 213 | } |
| 214 | | 214 | |
| 215 | if err := s.store.StoreFetchResult(ctx, feed.URL, result.Articles, faviconURL); err != nil { | 215 | if err := s.store.StoreFetchResult(ctx, feed.URL, result.Articles, faviconURL); err != nil { |