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, associated types, and settings types #1825

Draft
wants to merge 17 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 Settings types
  • 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

Waiting on #1741 ...

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 98.89381% with 5 lines in your changes missing coverage. Please review.

Project coverage is 97.68%. Comparing base (c2af858) to head (ccd5c20).

Files with missing lines Patch % Lines
src/indexes.ts 98.60% 4 Missing ⚠️
src/task.ts 99.03% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1825      +/-   ##
==========================================
- Coverage   98.21%   97.68%   -0.53%     
==========================================
  Files          17       18       +1     
  Lines        1565     1470      -95     
  Branches      333      285      -48     
==========================================
- Hits         1537     1436     -101     
- Misses         28       34       +6     

☔ 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
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