What's the best way to automatically update data in a collection based on update in other collection
- 1
- Databases
- Functions
- Web
- Realtime
My project is similar to an e-commerce app. I have a like functionality. every user can see their liked products in their wishlist and every product has the count of how many users have liked it. For the wishlist, I have a users collection where there's a document for every user with the id same as the user id and it has only one attribute which is an array that contains ids of all the products a user has liked. For the Likes count, the products collection has a likes attribute which is an array that contains ids of all the users that has liked the product.
Earlier i was updating both collections whenever a user adds or removes a product from wishlist (i.e. likes or unlikes) but soon i realised that updating product data manually isn't a good idea since it'll have a concurrency problem. So i used appwrite relationships. now whenever i update data in users collection, it automatically updates the products data coz it's a two way many to many collection. But now i have a new problem. now the Arrays don't just have the ids but they have the whole objects. eg. the array in products collection returns all the attributes of the user with associated id and same thing with the users array. as the users and products grow, the size increased and now the requests are very slow. like it takes almost 10 seconds to load the products data which was almost instantaneous earlier.
Is there a way to only add user ids of the users who liked the products instead of adding their whole document? or even a way to just increase or decrease a likes count based on updates in the users collection? please help. Sorry for the long message, I thought I should make the situation clear.
Recommended threads
- Functions not executing after usage rese...
Hi team, Last month my project hit 100% usage and functions stopped working (expected). Now the new month has started and usage has reset, requests are going ...
- Relations within the same table
Hello, I'm currently building a sort of dictionary (a literal one) and thus I need words (which is one single table of words in my database) to be able to have ...
- Functions never end and always fail (sta...
Hi ! I'm using Appwrite Cloud Pro and function execution from appwrite website is KO. Deploying starter function template, execution is always Failed and the ...