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

chore: blobStore.setDownloadFilter() & createEntriesReadableStream() #940

Merged
merged 29 commits into from
Nov 5, 2024

Conversation

gmaclennan
Copy link
Member

@gmaclennan gmaclennan commented Oct 23, 2024

Fixes #681

  • Removes blobStore.download() and the LiveDownload class.
  • Adds blobStore.createEntriesReadableStream() which is a stream of all entries in the blob store, filtered by blob type and variant(s).
  • Changes behaviour of BlobStore to auto-download blobs according to a downloadFilter.
  • Changes the BlobStore filter according to isArchiveDevice setting.
  • Changes the behaviour of CoreManager to not auto-download blob cores (this responsibility is now with BlobStore).

TODO:

  • Add e2e tests for blob downloads for non-archive device (see BlobStore unit tests for example).

@gmaclennan gmaclennan self-assigned this Oct 23, 2024
@gmaclennan gmaclennan marked this pull request as ready for review October 29, 2024 11:36
@gmaclennan gmaclennan changed the title WIP: blobStore.entriesStream() chore: blobStore.setDownloadFilter() & createEntriesReadableStream() Oct 29, 2024
@gmaclennan gmaclennan requested a review from EvanHahn October 29, 2024 12:46
Copy link
Contributor

@EvanHahn EvanHahn left a comment

Choose a reason for hiding this comment

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

Clean implementation. Left a bunch of comments but LGTM overall.

types/hyperdrive.d.ts Outdated Show resolved Hide resolved
types/hyperbee.d.ts Outdated Show resolved Hide resolved
types/hyperbee.d.ts Outdated Show resolved Hide resolved
types/hyperbee.d.ts Show resolved Hide resolved
src/mapeo-project.js Show resolved Hide resolved
src/blob-store/entries-stream.js Outdated Show resolved Hide resolved
const coreManager = createCoreManager(...args)
const blobStore = new BlobStore({ coreManager })
return { blobStore, coreManager }
test('blobStore.createEntriesReadStream({ live: false })', async (t) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

As I said earlier, do we ever (plan to) use live: false? If not, could we remove this test?

src/blob-store/downloader.js Outdated Show resolved Hide resolved
src/blob-store/downloader.js Show resolved Hide resolved
src/blob-store/downloader.js Outdated Show resolved Hide resolved
@EvanHahn EvanHahn assigned EvanHahn and unassigned gmaclennan Oct 30, 2024
@EvanHahn EvanHahn force-pushed the chore/entries-stream branch from 8287f62 to 6496672 Compare November 4, 2024 00:40
Before this change, we turned filters into a list of path prefixes and
then checked entry paths against those prefixes. Rough pseudocode:

```javascript
function doesEntryMatchFilter({ path }, filter) {
  const pathPrefixes = pathPrefixesFromFilter(filter)
  return pathPrefixes.some((prefix) => path.startsWith(prefix))
}
```

For performance and simplicity, I think it's cleaner if we "look up"
entry paths in the existing filter object. Rough pseudocode:

```javascript
function doesEntryMatchFilter({ path }, filter) {
  const { type, variant } = parsePath(path)
  return filter[type]?.includes(variant)
}
```

I think this has two advantages:

- It's less code. We don't need to worry about de-duping paths (e.g.,
  `/photos/original` versus `/photos/`). We don't need to worry about
  sketchy paths (e.g., `/photos/garbage/../original`).
- It's faster (at least, in theory). Rather than having to iterate over
  every path prefix, we only need to iterate over the variants of each
  path. (This could be further optimized with a `Set`.)
@EvanHahn EvanHahn changed the base branch from main to media-manager-v1 November 5, 2024 20:47
@EvanHahn
Copy link
Contributor

EvanHahn commented Nov 5, 2024

Added end-to-end tests in d374b20.

This will currently break if deployed. If you set yourself as a non-archive device, sync will be partially broken. I'm going to merge this into the media-manager-v1 branch until it's ready to deploy.

@EvanHahn EvanHahn merged commit 0a2db23 into media-manager-v1 Nov 5, 2024
9 checks passed
@EvanHahn EvanHahn deleted the chore/entries-stream branch November 5, 2024 20:52
EvanHahn added a commit that referenced this pull request Nov 7, 2024
…)` (#940)

- Removes `blobStore.download()` and the `LiveDownload` class.
- Adds `blobStore.createEntriesReadableStream()` which is a stream of
  all entries in the blob store, filtered by blob type and variant(s).
- Changes behaviour of `BlobStore` to auto-download blobs according to a
  `downloadFilter`.
- Changes the `BlobStore` filter according to `isArchiveDevice` setting.
- Changes the behaviour of `CoreManager` to not auto-download blob cores
  (this responsibility is now with `BlobStore`).

Closes [#681].

[#681]: #681

Co-authored-by: Evan Hahn <[email protected]>
@EvanHahn EvanHahn mentioned this pull request Nov 20, 2024
EvanHahn added a commit that referenced this pull request Nov 20, 2024
This is a squashed commit of:

- #940
- #957
- #956

Co-authored-by: Gregor MacLennan <[email protected]>
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.

Adjust blob store download to selectively download only photo previews and thumbnails based on device setting
2 participants