
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
- Network Request Failed
Trying to save a file to the bucket but getting network request failed. Using react-native-image-picker.
- Unable to set Display Name for Collectio...
In database: Collection -> Settings. Display Name: Add attribute -> Select attribute -> After selecting attribute, the "Select attribute" text still shows. A...
- Redirect URL sends HTTP instead of HTTPS...
I am not sure since when this issue is present, but my Google and Apple redirect URI are no longer pointing to the HTTPS redirect URI when I try to use OAuth. ...
