Back

Best way to implement upload of favorites

  • 0
  • Databases
  • Flutter
frankenstein
27 Sep, 2023, 11:41

am developing an ecommerce ive created an appwrite collection for favorites. i fetch it when the user logs in but i dont want to upload a list everytime a user likes a product i want to upload once when user minimizes or closes the app or logs out so that to reduce number of uploads. Whats the best way to handle favorites?

TL;DR
The user is asking for the best way to handle favorites in their ecommerce app. Several suggestions are made, including avoiding relying on the app closing or being put in the background to write to the database. Storing favorites as user-specific documents with permissions is recommended to avoid issues with growing lists. Using a function or WorkManager is also suggested for uploading favorites later. The user should consider making each favorited item a separate record for easier additions and deletions. Storing the favorites locally and using something like WorkManager to upload later is another option.
darShan
27 Sep, 2023, 12:28

Store the favs. locally, use something like a workmanager to upload later.

Ernest
27 Sep, 2023, 12:28

Is a favourited item a record in the collection or it's an entry in an array? If the latter is true, would making each favourited item a record pose a problem? IMO having each item as a record makes additions/deletions easier.

darShan
27 Sep, 2023, 12:30

If it would be an array, this "could" cause issues later maybe since the list would grow and grow at some point. A better way would be to keep user specific documents for their favs & set permissions to that user only. A function could be used, something like WorkManager works fine as well in this case.

Ernest
27 Sep, 2023, 12:36

Yes! That's how I would approach it too. I wouldn't bet on 100% write success when the app is exiting or being put in the background. Some OEM androids are aggressive with killing background tasks. Heck! I have deliberately turned on aggressive killing of background tasks for most apps on my phone

hamed
27 Sep, 2023, 13:00

That's true. In my case, I use a text file for each user's record, and I store them in a specific storage bucket. This approach helps avoid potential issues with growing lists and allows for user-specific documents with permissions

frankenstein
27 Sep, 2023, 22:22

Lemme look into it

frankenstein
27 Sep, 2023, 22:25

So favorites as documents is better than favorites as an array

Ernest
28 Sep, 2023, 08:27

IMO yes. I would use an array for items that I know wouldn't would grow as much.

frankenstein
28 Sep, 2023, 08:28

How much are considering like 50+ or 100+

Ernest
28 Sep, 2023, 08:35

I'd say 100+

frankenstein
28 Sep, 2023, 08:39

Okay that's fine

frankenstein
28 Sep, 2023, 08:40

For social media it's easier to exceed 100 for liked posts but like ecommerce I don't expect to exceed 100

Ernest
28 Sep, 2023, 08:47

Depends on the kind of ecommerce app. In any case, the main point is relying on the app closing or being put in the background to write to the DB is not ideal

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more