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

Add async overload for search API #410

Merged
merged 3 commits into from
Sep 28, 2023

Conversation

Sherlouk
Copy link
Collaborator

@Sherlouk Sherlouk commented Sep 16, 2023

Pull Request

⚠️ I've marked this as draft as it current works to provide an example of how we could add async/await support to the library. I am more than happy to expand this to all currently supported APIs.

Related issue

Relates to #332 (doesn't close as only adds support for one API)

What does this PR do?

  • Adds an async/await override to an existing search API providing users with more choice.

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!

@Sherlouk Sherlouk mentioned this pull request Sep 16, 2023
Copy link
Contributor

@aronbudinszky aronbudinszky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from the minor comment regarding fileprivate all looks good to me!

I have not actually tested it though, but assume it does work given that the unit test passes.

@@ -26,7 +26,7 @@ public struct Indexes {
private let documents: Documents

// Search methods
private let search: Search
fileprivate let search: Search
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is actually not required - private will work just as fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me double check this, I thought I had a compiler error when I tested (due to use of an extension) but will double check and revert if possible.

In respect of "I have not actually tested it though" - I'm using this in a production application and is working fine for me 🙂 Though I'll keep an eye on it!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I've moved this to internal for the sole reason of improving readability and maintenance. I'm not keen while we're in this split world to have every implementation in one file, I think it'll get a bit much. Internal allows us to break it down into two files (and eventually get rid of one when we only have async). Hope this works for you 🙂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's fair, agreed. (If there is value in hiding these properties internally we could still use protocols for that - though not sure if it is necessary.)

Only final point that I'd make then is that I would not explicitly state internal - given that this is the default anyway and not used on other internal properties.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, that's a personal preference but deviates from standard practice for the project. I'll amend in a follow up PR

@curquiza
Copy link
Member

Thank you @aronbudinszky for reviewing and @Sherlouk for the PR

Can you confirm there is no breaking for the user? 😊
Is this change worth adding some documentation to the README? Or is ti really "usage transparent"?

@Sherlouk
Copy link
Collaborator Author

This is not a breaking change, no.
I do think it's worth updating documentation with a quick example, but it is also obvious when using.

This acts as an example for the conversation being held in issue meilisearch#332.

Async/await continues to grow in popularity and all modern codebases are moving towards its usage. This commit demonstrates how we can add support for Swift Concurrency without breaking existing compatibility with older operating systems.

For a test I have taken an existing test, copied it, and converted it for async/await. In this instance, removing the XCTestExpectation and simply using an async test available since Xcode 13 back in September 2021.
I believe as we increase this implementation to support more APIs, it will become unwieldly stuck in one file. This commit pulls it out into a separate directory for ease of maintenance.
@Sherlouk Sherlouk marked this pull request as ready for review September 28, 2023 13:24
@Sherlouk
Copy link
Collaborator Author

Sherlouk commented Sep 28, 2023

I've updated documentation, tweaked implementation, and opened up the PR. This does only add support for one API (search), but if we're happy then I can either:

  1. Merge this PR, and then open a new one with support for all other APIs
  2. Keep this PR open, until I've added support for all other APIs
  3. Merge this PR, but open support for each other API one PR at a time (as I work on them with other features).

Clem, thoughts?

My opinion would be #1 or #2 as the async code is very repetitive and so shouldn't be a chore to review (though large) - but might get confusing if mixed in with other features. This'll help to get support quickly to the project. I might do some test refactoring too to enable reuse but validate all behaviour.

@curquiza
Copy link
Member

Let's go with #1, not with #3 indeed 😄

Copy link
Member

@curquiza curquiza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors merge

@curquiza curquiza added the enhancement New feature or request label Sep 28, 2023
@meili-bors
Copy link
Contributor

meili-bors bot commented Sep 28, 2023

@meili-bors meili-bors bot merged commit 1d68308 into meilisearch:main Sep 28, 2023
@aronbudinszky
Copy link
Contributor

Btw retroactively confirming there is no breaking change. :)

Sherlouk added a commit to Sherlouk/meilisearch-swift that referenced this pull request Oct 1, 2023
Sherlouk added a commit to Sherlouk/meilisearch-swift that referenced this pull request Oct 14, 2023
meili-bors bot added a commit that referenced this pull request Nov 2, 2023
427: Generate Async Overloads for All Public Functions r=Sherlouk a=Sherlouk

# Pull Request

## Related issue
Fixes #332 

This is NOT a breaking change.

## What does this PR do?
- Adds async/await overloads to all public interfaces.

The contents of these files has been automatically generated using [Sourcery](https://github.com/krzysztofzablocki/Sourcery) using [this template](https://gist.github.com/Sherlouk/fa3e49e24f9be7232c642b945177b05e) I made. It does not include documentation, I feel like this is an okay compromise at this point in time and is something that can be incremented on in the future, potentially when we move over entirely. Async/Await functions sit in Xcode along with the normal closure based methods and so is easy to see the documentation inline anyway.

The template has been shared to hopefully make it easier to update when new APIs are added in the future, keeping maintenance down.

With the previous PR (#410) I called the underlying implementation directly, this leads to unnecessary duplication with other functions. Instead I call the non-async function guaranteeing consistent functionality, and no unnecessary duplication. I also feel like this avoids the need for excessive and additional test coverage, so long as the build compiles then the implementation is working as expected and tests give us no extra confidence that it's working as expected. We'll keep the one for search to demonstrate.

`@aronbudinszky` Are you happy with this approach too?

## PR checklist
Please check if your PR fulfills the following requirements:
- [x] Does this PR fix an existing issue, or have you listed the changes applied in the PR description (and why they are needed)?
- [x] Have you read the contributing guidelines?
- [x] Have you made sure that the title is accurate and descriptive of the changes?

Thank you so much for contributing to Meilisearch!


Co-authored-by: James Sherlock <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants