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
- How to Avoid Double Requests in function...
I'm currently using Appwrite's `functions.createExecution` in my project. I want to avoid double requests when multiple actions (like searching or pagination) a...
- Send Email Verification With REST
I am using REST to create a user on the server side after receiving form data from the client. After the account is successfully created i wanted to send the v...
- Use different email hosts for different ...
Hello, I have 2 projects and i want to be able to set up email templates in the projects. Both projects will have different email host configurations. I see ...