You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "AryanBagade (via GitHub)" <gi...@apache.org> on 2025/11/28 12:47:11 UTC

[PR] fix(services/huggingface): Implement pagination with Link header for large repos [opendal]

AryanBagade opened a new pull request, #6832:
URL: https://github.com/apache/opendal/pull/6832

   This commit fixes list truncation on large HuggingFace repositories by implementing proper pagination support following the Hub tree API.
   
   
   
   # Which issue does this PR close?
   Fixes #6830 (part 2)
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   
   # Rationale for this change
   
   Currently, when listing files in large HuggingFace repositories, only the first page of results is returned, causing truncation. The HuggingFace Hub API uses Link headers with `rel="next"` for pagination (RFC 8288), but the existing implementation sets `ctx.done = true` immediately after the first response, preventing subsequent pages from being fetched.
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   # What changes are included in this PR?
   
   **Core changes:**
     - Added `parse_link_header()` function in `lister.rs` to parse RFC 8288 Link headers
     - Modified `HuggingfaceLister::next_page()` to check for next page URL and store it in `ctx.token`
     - Updated `hf_list()` in `core.rs` to accept optional cursor parameter
     - Added `hf_list_with_url()` method to fetch subsequent pages using full URL from Link header
   
   **Tests added:**
     - 5 unit tests for Link header parsing covering various formats and edge cases
     - 1 integration test for cursor parameter handling
   
   The implementation follows the same pattern used by the OneDrive service for consistency.
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   
   **Yes - Behavior improvement:**  Users listing large HuggingFace repositories will now receive **all files** instead of only the first page. This is a bug fix with no breaking changes to the API.
   
   **No action required from users** - the pagination happens automatically and transparently.
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking-changes` label.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(services/huggingface): Implement pagination with Link header for large repos [opendal]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #6832:
URL: https://github.com/apache/opendal/pull/6832#discussion_r2572810979


##########
core/src/services/huggingface/lister.rs:
##########
@@ -89,3 +102,105 @@ impl oio::PageList for HuggingfaceLister {
         Ok(())
     }
 }
+
+/// Parse the Link header to extract the next page URL.
+/// HuggingFace API returns pagination info in the Link header with rel="next".
+/// Example: <https://huggingface.co/api/models/.../tree?cursor=xxx>; rel="next"
+fn parse_link_header(headers: &http::HeaderMap) -> Option<String> {
+    let link_header = headers.get(http::header::LINK)?;
+    let link_str = link_header.to_str().ok()?;
+
+    // Parse Link header format: <url>; rel="next"
+    for link in link_str.split(',') {
+        let link = link.trim();
+        if link.contains("rel=\"next\"") || link.contains("rel='next'") {
+            // Extract URL from <url>
+            if let Some(start) = link.find('<') {
+                if let Some(end) = link.find('>') {
+                    return Some(link[start + 1..end].to_string());
+                }
+            }

Review Comment:
   How about using:
   
   ```
   let (_, rest) = link.split_once('<')?;
   let (inside, _) = rest.split_once('>')?;
   return Some(inside.to_string());
   ```



##########
core/src/services/huggingface/lister.rs:
##########
@@ -89,3 +102,105 @@ impl oio::PageList for HuggingfaceLister {
         Ok(())
     }
 }
+
+/// Parse the Link header to extract the next page URL.
+/// HuggingFace API returns pagination info in the Link header with rel="next".
+/// Example: <https://huggingface.co/api/models/.../tree?cursor=xxx>; rel="next"
+fn parse_link_header(headers: &http::HeaderMap) -> Option<String> {
+    let link_header = headers.get(http::header::LINK)?;
+    let link_str = link_header.to_str().ok()?;
+
+    // Parse Link header format: <url>; rel="next"
+    for link in link_str.split(',') {
+        let link = link.trim();

Review Comment:
   I think We don't need to trim here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(services/huggingface): Implement pagination with Link header for large repos [opendal]

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo merged PR #6832:
URL: https://github.com/apache/opendal/pull/6832


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] fix(services/huggingface): Implement pagination with Link header for large repos [opendal]

Posted by "AryanBagade (via GitHub)" <gi...@apache.org>.
AryanBagade commented on code in PR #6832:
URL: https://github.com/apache/opendal/pull/6832#discussion_r2572827668


##########
core/src/services/huggingface/lister.rs:
##########
@@ -89,3 +102,105 @@ impl oio::PageList for HuggingfaceLister {
         Ok(())
     }
 }
+
+/// Parse the Link header to extract the next page URL.
+/// HuggingFace API returns pagination info in the Link header with rel="next".
+/// Example: <https://huggingface.co/api/models/.../tree?cursor=xxx>; rel="next"
+fn parse_link_header(headers: &http::HeaderMap) -> Option<String> {
+    let link_header = headers.get(http::header::LINK)?;
+    let link_str = link_header.to_str().ok()?;
+
+    // Parse Link header format: <url>; rel="next"
+    for link in link_str.split(',') {
+        let link = link.trim();
+        if link.contains("rel=\"next\"") || link.contains("rel='next'") {
+            // Extract URL from <url>
+            if let Some(start) = link.find('<') {
+                if let Some(end) = link.find('>') {
+                    return Some(link[start + 1..end].to_string());
+                }
+            }

Review Comment:
   sure



##########
core/src/services/huggingface/lister.rs:
##########
@@ -89,3 +102,105 @@ impl oio::PageList for HuggingfaceLister {
         Ok(())
     }
 }
+
+/// Parse the Link header to extract the next page URL.
+/// HuggingFace API returns pagination info in the Link header with rel="next".
+/// Example: <https://huggingface.co/api/models/.../tree?cursor=xxx>; rel="next"
+fn parse_link_header(headers: &http::HeaderMap) -> Option<String> {
+    let link_header = headers.get(http::header::LINK)?;
+    let link_str = link_header.to_str().ok()?;
+
+    // Parse Link header format: <url>; rel="next"
+    for link in link_str.split(',') {
+        let link = link.trim();

Review Comment:
   done 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org