Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve TaskClient, BatchClient and associated types #1825

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from

Conversation

flevi29
Copy link
Collaborator

@flevi29 flevi29 commented Jan 13, 2025

Pull Request

What does this PR do?

  • remove classes Batch, EnqueuedTask and Task
    • these had no other functionality other than to re-create their *Object equivalent objects, that come from the API responses, for the most part with the same exact properties and values
    • some of them converted date strings to Date objects, but this functionality is also being removed, because:
      • most users don't use these properties, so for them it's just extra useless processing
      • maybe users want to use a different date object, like the upcoming Temporal API, or Luxon or any other
  • improve, fix, adjust and document types, with the help of meilisearch Rust source code
    • rename type EnqueuedTaskObject to EnqueuedTask
      • remove canceledBy property as it doesn't exist
      • indexUid property cannot be undefined but can be null
    • rename type BatchObject to Batch, adjust properties
    • rename type TaskObject to Task, adjust properties
      • for instance Task.details had quite a few properties missing, like pagination, now it's reusing the Settings type, so we don't repeat ourselves
  • rework and document TaskClient
    • methods now make use of setInterval
    • default interval delay changed: 50ms -> 200ms
      • 200ms is still 5x a second, 50ms was 20x a second, which was a little too spammy as a default in my opinion, but we can change this
    • there are no additional getTask requests sent until the previous one finishes (less spam, more efficient)
    • can now accept task uid number or an EnqueuedTask object as parameter
    • waitForTasks can now accept an iterable instead of just an array as parameter
    • new method waitForTasksIter, which is an asynchronous generator, that lazily awaits the tasks
  • every method that returned a Promise<EnqueuedTask> now instead returns an EnqueuedTaskPromise
    • this is a Promise<EnqueuedTask> with an extra method waitTask, that first gets the EnqueuedTask and then internally calls TaskClient.waitForTask on it to return a Promise<Task>, avoiding quite a bit of boilerplate

PR checklist

Please check if your PR fulfills the following requirements:

  • Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
  • Have you read the contributing guidelines?
  • Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!

TODO: also create a new issue regarding testing and auto generating code samples

@flevi29 flevi29 added enhancement New feature or request breaking-change The related changes are breaking for the users labels Jan 13, 2025
Copy link

codecov bot commented Jan 13, 2025

Codecov Report

Attention: Patch coverage is 97.93510% with 7 lines in your changes missing coverage. Please review.

Project coverage is 98.15%. Comparing base (792ce67) to head (d2b3234).

Files with missing lines Patch % Lines
src/indexes.ts 97.60% 4 Missing ⚠️
src/task.ts 97.32% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1825      +/-   ##
==========================================
- Coverage   98.84%   98.15%   -0.70%     
==========================================
  Files          17       18       +1     
  Lines        1565     1411     -154     
  Branches      338      289      -49     
==========================================
- Hits         1547     1385     -162     
- Misses         18       26       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@flevi29 flevi29 added the bug Something isn't working label Jan 15, 2025
@flevi29 flevi29 changed the title Improve TaskClient, BatchClient, associated types, and settings types Improve TaskClient, BatchClient and associated types Jan 28, 2025
@flevi29 flevi29 marked this pull request as ready for review January 30, 2025 08:10
@flevi29
Copy link
Collaborator Author

flevi29 commented Jan 30, 2025

For some reason it's a lot slower, whereas it should be faster. I'll investigate.

@flevi29 flevi29 marked this pull request as draft January 30, 2025 11:43
@flevi29
Copy link
Collaborator Author

flevi29 commented Jan 30, 2025

Okay, solved the slowness problem.

Next, there's a lot of apply wait task. Should probably integrate it with http requests instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change The related changes are breaking for the users bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant