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

Open
wants to merge 42 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
    • refactor waitForTask, now it uses setTimeout for timeout instead of inaccurate expensive date calculations
    • can now accept task uid number or an EnqueuedTask object as parameter
    • waitForTasks can now accept an iterable or an asynchronous 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
  • new property on Config: defaultWaitOptions - used to set the default wait options for TaskClient
  • reduce interval for waiting tasks in tests, thus making tests complete often in under 2 minutes
  • waiting on Remove hint about bad Meilisearch version #1848

Caution

  • TaskClient is no longer exported, use it through Meilisearch or Index instead, on both available as tasks property
    • this brings it in line with BatchClient which isn't exported in the index file
  • Batch class is only a type now
  • EnqueuedTask class is only a type now
  • Task class is only a type now
  • any property on the 3 items above that was a Date before is now a string
    • conversion to Date is left to the user (new Date(str))

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!

@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

All modified and coverable lines are covered by tests ✅

Project coverage is 98.71%. Comparing base (698f7e9) to head (3156692).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1825      +/-   ##
==========================================
- Coverage   98.84%   98.71%   -0.14%     
==========================================
  Files          17       17              
  Lines        1565     1400     -165     
  Branches      338      291      -47     
==========================================
- Hits         1547     1382     -165     
  Misses         18       18              

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

@flevi29 flevi29 requested a review from Strift January 31, 2025 12:11
@flevi29 flevi29 marked this pull request as ready for review January 31, 2025 12:11
@flevi29 flevi29 added the maintenance Issue about maintenance (CI, tests, refacto...) label Jan 31, 2025
@flevi29 flevi29 linked an issue Feb 3, 2025 that may be closed by this pull request
6 tasks
@flevi29 flevi29 mentioned this pull request Feb 4, 2025
6 tasks
@flevi29 flevi29 removed a link to an issue Feb 4, 2025
6 tasks
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 maintenance Issue about maintenance (CI, tests, refacto...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant