From be27625a3cba10a4c27760b09dfabddcdab28b40 Mon Sep 17 00:00:00 2001 From: mkelvers Date: Mon, 1 Jun 2026 22:21:19 +0200 Subject: [PATCH] refactor: dedupe jikan refresh --- integrations/jikan/anime.go | 15 ++------------- integrations/jikan/client.go | 8 +++++++- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/integrations/jikan/anime.go b/integrations/jikan/anime.go index 37b87ca..c4ff870 100644 --- a/integrations/jikan/anime.go +++ b/integrations/jikan/anime.go @@ -94,18 +94,7 @@ func (c *Client) refreshAnimeByID(ctx context.Context, id int) (Anime, error) { } func (c *Client) refreshAnimeByIDAsync(id int) { - select { - case c.refreshSem <- struct{}{}: - default: - return - } - - go func() { - defer func() { <-c.refreshSem }() - - ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) - defer cancel() - + c.runAsyncRefresh(func(ctx context.Context) { _, _ = c.refreshAnimeByID(ctx, id) - }() + }) } diff --git a/integrations/jikan/client.go b/integrations/jikan/client.go index 3bbcd01..717493d 100644 --- a/integrations/jikan/client.go +++ b/integrations/jikan/client.go @@ -410,6 +410,12 @@ func (c *Client) refreshWithCacheAsync(cacheKey string, ttl time.Duration, url s return } + c.runAsyncRefresh(func(ctx context.Context) { + _ = c.refreshWithCache(ctx, cacheKey, ttl, url, target) + }) +} + +func (c *Client) runAsyncRefresh(refresh func(context.Context)) { select { case c.refreshSem <- struct{}{}: default: @@ -422,7 +428,7 @@ func (c *Client) refreshWithCacheAsync(cacheKey string, ttl time.Duration, url s ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) defer cancel() - _ = c.refreshWithCache(ctx, cacheKey, ttl, url, target) + refresh(ctx) }() }