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

Cache mechanism for photos #1595

Closed
g123k opened this issue Apr 17, 2022 · 5 comments · Fixed by #1600
Closed

Cache mechanism for photos #1595

g123k opened this issue Apr 17, 2022 · 5 comments · Fixed by #1600
Assignees
Labels
✏️ Contribution Product addition The easier it is to add a product and get Nutri-Score, Eco-Score, the happier the users.
Milestone

Comments

@g123k
Copy link
Collaborator

g123k commented Apr 17, 2022

What

If we migrate to a non-blocking uploading photo feature (#1593), we have to implement a local cache.
Indeed, if a photo is not yet sent to the server (offline mode for example), the user shouldn't be aware of that.

The change required here is basically to say:

  • Is a photo available in the cache? -> If true, take it
  • Otherwise, make a request

The idea is to use this folder: https://pub.dev/documentation/path_provider/latest/path_provider/getTemporaryDirectory.html
When a new task is created, the photo is stored there and removed once the task is successful.

Part of

@g123k g123k added the Product addition The easier it is to add a product and get Nutri-Score, Eco-Score, the happier the users. label Apr 17, 2022
@g123k g123k added this to the V1 milestone Apr 17, 2022
@g123k g123k self-assigned this Apr 17, 2022
@monsieurtanuki
Copy link
Contributor

@g123k I don't think it's safe to use a temporary directory, as "Files in this directory may be cleared at any time." (it means: when other apps need space).
The files we're talking about are files that the user assume are to be uploaded; we don't want those files to be deleted from out of nowhere.
I suggest getApplicationDocumentsDirectory instead.

You're not mentioning either the fact that some day we'll have to upload the pictures (and delete them).

Or maybe there's confusion with #413 and #1593.

I do think those are distinct issues:

  • non-blocking upload (safe folder)
  • cache (tmp folder)
  • special case of user when the upload is not finished - check in the safe folder, then in the cache folder, then a request?

@g123k
Copy link
Collaborator Author

g123k commented Apr 17, 2022

Yes and no.

On Android, it's only based on the user's decision.
However, you're right, on iOS, it may be erased by the OS.
Hence, my confusion on this.

Also, after reading how Hive is implemented, it also uses getApplicationDocumentsDirectory. So we should follow the same impl.

Thanks for your feedback.

This issue is indeed for #1593, as this cache is only temporary, whereas #413 is a long-living cache.

You're not mentioning either the fact that some day we'll have to upload the pictures (and delete them).
That's what will be done in #1593

To summarize, this issue only consists in implementing a system to store temporary files while they're being uploaded.

@monsieurtanuki
Copy link
Contributor

@g123k Thank you for your answer.

I still don't agree on several points:

@g123k
Copy link
Collaborator Author

g123k commented Apr 18, 2022

A PR #1600 is available with both short and long living cache storage.

Hmmm I’m not sure to understand your last point.
For the cache mechanism implementation (what I’ve done in the PR) to which issue will it be linked?

@monsieurtanuki
Copy link
Contributor

@g123k Actually you fixed both cases (cache and to-be-uploaded) in just one PR, so you can ignore my last point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✏️ Contribution Product addition The easier it is to add a product and get Nutri-Score, Eco-Score, the happier the users.
3 participants