Skip to content

Conversation

Copy link

Copilot AI commented Sep 8, 2025

This PR implements a batch upload system to replace the inefficient sequential POST calls for book indexing, addressing the issue described in the repository's TODO list.

Problem

The existing implementation processed multiple book uploads by making individual POST requests in a loop, which resulted in:

  • N separate HTTP requests for N books
  • Redundant metadata processing for each book
  • Poor performance and user experience
  • Increased network overhead
// Before: Sequential uploads in a loop
for (let i = 0; i < bookDatas.length; i++) {
    const res = await uploadBook(book); // Individual POST /books
}

Solution

Implemented a new batch upload endpoint that processes multiple books in a single request:

Backend Changes

  • New endpoint: POST /books/batch that accepts multiple books and metadata arrays
  • Efficient processing: Shared metadata (authors, tags, series) processed once
  • Proper error handling: Detailed success/failure status for each book in the batch
  • Transaction integrity: Maintains database consistency with proper error handling

Frontend Changes

  • Single API call: Replaced the upload loop with one batch request
  • Improved UX: Better progress reporting and error feedback
  • Enhanced error handling: Displays detailed results for partial batch failures
// After: Single batch upload
const formData = new FormData();
// Add all books and metadata
bookDatas.forEach(book => {
    formData.append("books", book.file);
    formData.append("titles", book.title);
    // ...
});

const res = await fetch(`${API_HOST}/books/batch`, {
    method: "POST",
    body: formData
});

Benefits

  • Performance: Single HTTP request reduces network overhead
  • Efficiency: Shared metadata processing reduces database operations
  • Reliability: Better transaction handling with comprehensive error reporting
  • User Experience: Faster uploads with clear success/failure feedback

Testing

  • Backend compiles successfully with new batch endpoint
  • Frontend builds without TypeScript errors
  • Maintains all existing validation and UI behavior
  • Preserves original series and cover handling logic

This change directly addresses the TODO item: "Use a bulk post instead of a post for each book" while maintaining backward compatibility and all existing functionality.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 3 commits September 8, 2025 11:51
Co-authored-by: Bastien2203 <48283813+Bastien2203@users.noreply.github.com>
Co-authored-by: Bastien2203 <48283813+Bastien2203@users.noreply.github.com>
Co-authored-by: Bastien2203 <48283813+Bastien2203@users.noreply.github.com>
Copilot AI changed the title [WIP] replace post call to index book by a batch call Replace sequential book uploads with batch API call Sep 8, 2025
Copilot AI requested a review from Bastien2203 September 8, 2025 12:01
Copilot finished work on behalf of Bastien2203 September 8, 2025 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants