diff options
| author | Bobby <[email protected]> | 2026-02-06 18:07:07 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-02-06 18:07:07 +0530 |
| commit | 31b5543be4faa4f01946d532d4b5e34828b285b5 (patch) | |
| tree | 393bb47243d6a68849e5de04ee4ef6931f7cd990 /utils/api | |
| parent | 2f4220364665b5b52dbee8c549e68ea9da46df21 (diff) | |
| download | metachan-31b5543be4faa4f01946d532d4b5e34828b285b5.tar.xz metachan-31b5543be4faa4f01946d532d4b5e34828b285b5.zip | |
Refactor Jikan API client: improve context management in GetAnimeProducers and enhance logging for pagination
Diffstat (limited to 'utils/api')
| -rw-r--r-- | utils/api/jikan/jikan.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/utils/api/jikan/jikan.go b/utils/api/jikan/jikan.go index 920f6dc..87c7cfd 100644 --- a/utils/api/jikan/jikan.go +++ b/utils/api/jikan/jikan.go @@ -251,7 +251,6 @@ func GetAnimeByGenre(genreID int, page int, limit int) (*types.JikanAnimeSearchR func GetAnimeProducers() (*types.JikanProducersResponse, error) { url := fmt.Sprintf("%s/producers", jikanAPIBaseURL) - ctx, cancel := context.WithTimeout(context.Background(), contextTimeout) page := 1 hasNextPage := true @@ -260,12 +259,12 @@ func GetAnimeProducers() (*types.JikanProducersResponse, error) { Pagination: types.JikanGenericPaginationEntity{}, } - defer cancel() - for hasNextPage { pageURL := fmt.Sprintf("%s?page=%d", url, page) + ctx, cancel := context.WithTimeout(context.Background(), contextTimeout) bytes, err := clientInstance.makeRequest(ctx, pageURL) + cancel() if err != nil { logger.Errorf("JikanClient", "GetAnimeProducers failed on page %d: %v", page, err) return nil, errors.New("failed to fetch anime producers from Jikan API") @@ -281,6 +280,8 @@ func GetAnimeProducers() (*types.JikanProducersResponse, error) { response.Pagination = pageResponse.Pagination } + logger.Debugf("JikanClient", "Fetched page (%d/%d) - %d producers", page, response.Pagination.LastVisiblePage, len(pageResponse.Data)) + response.Data = append(response.Data, pageResponse.Data...) hasNextPage = pageResponse.Pagination.HasNextPage page++ |
