
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
- Runtime secret not found. Please re-crea...
Functions aren't working for my project suddenly, They worked fine for the past few weeks and were also working 15-20 minutes ago.
- Unable to see delete option to delete id...
see attached image.
- Google & Apple OAuth2 not working in App...
Two days ago, the OAuth2-based login/signup was working as expected. Today, when I try to log in with an existing user using Apple OAuth2, it shows the message ...
