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

feat: add use case to download assets by its asset key/id (AR-1094) #243

Merged
merged 74 commits into from
Mar 9, 2022

Conversation

yamilmedina
Copy link
Contributor

@yamilmedina yamilmedina commented Feb 28, 2022


PR Submission Checklist for internal contributors

  • The PR Title

    • conforms to the style of semantic commits messages¹ supported in Wire's Github Workflow²
    • contains a reference JIRA issue number like SQPIT-764
    • answers the question: If merged, this PR will: ... ³
  • The PR Description

    • is free of optional paragraphs and you have filled the relevant parts to the best of your ability

What's new in this PR?

Issues

https://wearezeta.atlassian.net/browse/AR-1094

This change includes the following aspects of downloading a public asset (user's avatar)

  • Use case to map the asset by its ID
  • Persist locally the binary data of the image
  • Return to the consumer application the image as a ByteArray

Dependencies (Optional)

This PR needs to be merged after
#241

Needs releases with:

  • GitHub link to other pull request

Attachments (Optional)


PR Post Submission Checklist for internal contributors (Optional)

  • Wire's Github Workflow has automatically linked the PR to a JIRA issue

PR Post Merge Checklist for internal contributors

  • If any soft of configuration variable was introduced by this PR, it has been added to the relevant documents and the CI jobs have been updated.

References
  1. https://sparkbox.com/foundry/semantic_commit_messages
  2. https://github.com/wireapp/.github#usage
  3. E.g. feat(conversation-list): Sort conversations by most emojis in the title #SQPIT-764.

@yamilmedina
Copy link
Contributor Author

@typfel @gongracr I made the changes here after our conversation, if you see specifically the last commit (eee3ed0) you'll see that now the sync it's happening in a one shot execution 🙌

My only concern it is with the slow sync (now it's actually slower), since the first time we have to download every contact avatar asset, it's a cost we have to assume with this approach. Anyway, after that first sync we don't have a performance degradation from what I could test, since the assets are already present and no download it's made after that.
Happy to receive your PR review guys 😄

@typfel
Copy link
Member

typfel commented Mar 4, 2022

My only concern it is with the slow sync (now it's actually slower), since the first time we have to download every contact avatar asset, it's a cost we have to assume with this approach. Anyway, after that first sync we don't have a performance degradation from what I could test, since the assets are already present and no download it's made after that.
Happy to receive your PR review guys

But why we are downloading the pictures during the slow sync? Why don't we download the profile pictures the first time we want display them in the UI.

assetRepository.saveUserPictureAsset(mapAssetsForUsersToBePersisted(usersToBePersisted))
// not sure about this, because on first sync it's taking ages =/
// options, doing it in 2 steps like before and downloading on demand or doing it somehow in a non.blocking fashion
assetRepository.downloadUsersPictureAssets(mapAssetsForUsersToBePersisted(usersToBePersisted))
Copy link
Member

Choose a reason for hiding this comment

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

Yes, we shouldn't do this here but on demand.

Copy link
Member

Choose a reason for hiding this comment

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

You already have everything for this though?

GetPublicAssetUseCase(user. previewPicture)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see an issue with this tough, because we have a FOREIGN KEY constraint on Users Table pointing to the Assets table. So the first time we need to persist in the assets table first, then the user (this was the reason of having the empty asset insert 😓 )

The option to achieve the on demand execution, that I also agree, will be removing the constraint and have the relation only at the Kotlin Model level 🤔 Would that make sense ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think it makes sense to remove the foreign key constraint in this case since we want to fetch it lazily.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied the changes, now we are not using anymore the FK constraint, and we are able to do the sync on demand later via usecase

import com.wire.kalium.logic.functional.suspending

interface GetPublicAssetUseCase {
suspend operator fun invoke(assetKey: String): Either<CoreFailure, ByteArray>
Copy link
Member

Choose a reason for hiding this comment

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

Can't we have assetKey be of type AssetId or UserAssetId?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, changes applied, completely agree that using this parameter suits it better

Base automatically changed from feat/add_assets_table to develop March 4, 2022 18:47
Copy link
Contributor

@gongracr gongracr left a comment

Choose a reason for hiding this comment

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

Looking in great shape now. GJ!! 🍙 🥢

@yamilmedina yamilmedina requested a review from typfel March 7, 2022 11:19
@typfel
Copy link
Member

typfel commented Mar 9, 2022

🚀

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.

3 participants