Skip to content

[Collection] Optimize collection fetch in search methods #3491

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

Merged
merged 1 commit into from
May 12, 2021

Conversation

yim-lee
Copy link
Contributor

@yim-lee yim-lee commented May 12, 2021

Motivation:
All the search methods in SQLitePackageCollectionsStorage start by fetching a subset or all of the collections from database. This is because prior to using FTS, search was done directly on the Collection instances. In case of FTS, we can optimize things by:

  1. Fetching collections from the database iff there are matches. i.e., return NotFoundError or empty result early
  2. Fetching only collections where matches are found

Modifications:
Rearrange logic in search methods to do the optimizations described above.

Related to rdar://77873780

Motivation:
All the search methods in `SQLitePackageCollectionsStorage` start by fetching a subset or all of the collections from database. This is because prior to using FTS, search was done directly on the `Collection` instances. In case of FTS, we can optimize things by:
1. Fetching collections from the database iff there are matches. i.e., return `NotFoundError` or empty result early
2. Fetching only collections where matches are found

Modifications:
Rearrange logic in search methods to do the optimizations described above.

Related to rdar://77873780
@yim-lee
Copy link
Contributor Author

yim-lee commented May 12, 2021

@swift-ci please smoke test

let packageQuery = "SELECT collection_id_blob_base64, repository_url FROM \(Self.packagesFTSName) WHERE \(Self.packagesFTSName) MATCH ?;"
try self.executeStatement(packageQuery) { statement in
try statement.bind([.string(query)])
if self.useSearchIndices.get() ?? false {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The diff is hard to read, but the changes in each method follow the same pattern: if self.useSearchIndices == true, call self.list(identifiers: identifiers) to fetch collections after we perform the search. This allows us to only fetch the collections we absolutely need.

Copy link
Contributor

@tomerd tomerd left a comment

Choose a reason for hiding this comment

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

nit: we can potentially make this easier to read by splitting into multiple functions.

@yim-lee yim-lee merged commit 1248164 into swiftlang:main May 12, 2021
@yim-lee yim-lee deleted the search-optimize branch May 12, 2021 22:29
bitjammer pushed a commit to bitjammer/swift-package-manager that referenced this pull request Jul 23, 2021
)

Motivation:
All the search methods in `SQLitePackageCollectionsStorage` start by fetching a subset or all of the collections from database. This is because prior to using FTS, search was done directly on the `Collection` instances. In case of FTS, we can optimize things by:
1. Fetching collections from the database iff there are matches. i.e., return `NotFoundError` or empty result early
2. Fetching only collections where matches are found

Modifications:
Rearrange logic in search methods to do the optimizations described above.

Related to rdar://77873780
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