
Each User profile has a like counter that accumulates from all posts.
A user has 10 posts. For each like executed , it should update the post and the total likes on the user’s profile. They are in separate COLLECTIONS
Would I use relationships? This is my execution and is probably not effective.
TypeScript
executeLike(int postLikes, String profileId) async {
int newLikes = postLikes + 1;
//update post
var status = await _databases.updateDocument(
databaseId: '...',
collectionId: 'posts',
documentId: '...',
data: {'likes': newLikes});
//get userprofile
var profileData = await _databases.getDocument(
databaseId: '...', collectionId: 'public_profile', documentId: profileId);
int totalLikes = profileData.data['total_likes'];
int newTotalLikes = totalLikes + 1;
// update poster's total likes
await _databases.updateDocument(
databaseId: '...',
collectionId: 'public_profile',
documentId: profileId,
data: {'total_likes': newTotalLikes});
}
TL;DR
The developer wants to update the like counter for a user's profile and their individual posts. They are currently executing this by updating the post's like count and then updating the user's total likes separately. They are unsure if this is the most effective method and asking for advice.
A more efficient solution would be to use relationships between the user profile and the posts. By creating a reference in the post document to the user's profile, you can easily update both the post's like count and the user's total likes in a single update operation.
The updated code would look something like this:
```dart
executeLike(int postLikes, String profileRecommended threads
- Stuck at pinging the server to finish ad...
I'm not using the starter app and I'm not sure how to finish connecting my app to Appwrite.io. Is there a CURL command I can run to finish setup?
- 500 internal error
I get a 500 internal error when trying to access my database on appwrite cloud. Sometimes it would start working but this time it never corrects.
- Error getting session: AppwriteException...
I get this error `Error getting session: AppwriteException: User (role: guests) missing scope (account)` when running in prod. As soon as I try running my app o...
