Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(feed): Properly get reactions from Posts endpoint #1396

Merged
merged 2 commits into from
Nov 21, 2024

Conversation

WaDadidou
Copy link
Collaborator

@WaDadidou WaDadidou commented Nov 18, 2024

Closes #1374

image

@WaDadidou WaDadidou added bug Something isn't working Social Feed Everything related to the Social Feed labels Nov 18, 2024
@WaDadidou WaDadidou self-assigned this Nov 18, 2024
Copy link

netlify bot commented Nov 18, 2024

Deploy Preview for teritori-dapp ready!

Name Link
🔨 Latest commit f1bdc82
🔍 Latest deploy log https://app.netlify.com/sites/teritori-dapp/deploys/673ce882ae54fb0008c2eac5
😎 Deploy Preview https://deploy-preview-1396--teritori-dapp.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Nov 18, 2024

Deploy Preview for testitori ready!

Name Link
🔨 Latest commit f1bdc82
🔍 Latest deploy log https://app.netlify.com/sites/testitori/deploys/673ce88260c0010008551256
😎 Deploy Preview https://deploy-preview-1396--testitori.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Comment on lines 175 to 181
reactionsMap := make(map[string]interface{})
if err := json.Unmarshal(dbPost.UserReactions, &reactionsMap); err != nil {
s.conf.Logger.Error("failed to unmarshal UserReactions", zap.String("data", string(dbPost.UserReactions)), zap.Error(err))
continue
}

dbPost.UserReactions.Scan(&reactionsMap)
Copy link
Collaborator

@n0izn0iz n0izn0iz Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't keep both Unmarshal and Scan

this scan is also used in the indexer so it's weird that it doesn't work here

Copy link
Collaborator Author

@WaDadidou WaDadidou Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work in indexer too :/

This post => https://app.teritori.com/feed/post/testori-caecb9c3-1a35-429b-be30-54c0578c8ec4

Service

image

Indexer

image

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@n0izn0iz should I make the same fix in the indexer ?
And removing the Scan usage

Copy link
Collaborator Author

@WaDadidou WaDadidou Nov 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 175 to 181
reactionsMap := make(map[string]interface{})
if err := json.Unmarshal(dbPost.UserReactions, &reactionsMap); err != nil {
s.conf.Logger.Error("failed to unmarshal UserReactions", zap.String("data", string(dbPost.UserReactions)), zap.Error(err))
continue
}

dbPost.UserReactions.Scan(&reactionsMap)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should handle the returned error here: dbPost.UserReactions.Scan(&reactionsMap)

if Scan does not work I think there is an error in the data (seems that empty map causes the error), if there data is corrupt then we should check from the source, if not then maybe .Scan does not work for empty data. We should use either unmarshal or scan but not both.

Copy link
Collaborator

@n0izn0iz n0izn0iz Nov 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem with scan comes from the change of type of from the custom jsonb encoder to the datatypes.JSON gorm type, we should use the gorm type IMO

Also the scan error should have been checked in the first place, I will add golangcilint checks to avoid that in the future

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so is it ok ? f1bdc82

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think json.Unmarshal will just unmarshal the data with defined struct so as long as it's compatible, it will work, that's the reason why the code works with json.Unmarshal (Scan might do some type check also so it does not work) because the root cause might be related to this:
Screenshot 2024-11-20 at 10 14 15 PM

so IMHO, the fix is valid, it can work but for the proper solution you should check the types change.

Copy link
Collaborator Author

@WaDadidou WaDadidou Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, look at this TODO: https://github.com/TERITORI/teritori-dapp/blob/fix-post-reactions-from-feed/go/internal/indexerdb/jsonb.go#L10
If we fix the TODO, UserReactions gets the type datatypes.JSON finally

@hthieu1110
Copy link
Collaborator

LGTM

Copy link
Collaborator

@n0izn0iz n0izn0iz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@n0izn0iz n0izn0iz enabled auto-merge November 20, 2024 17:55
Copy link
Collaborator

@hthieu1110 hthieu1110 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@n0izn0iz n0izn0iz added this pull request to the merge queue Nov 21, 2024
Merged via the queue into main with commit 1ea33f7 Nov 21, 2024
23 checks passed
@n0izn0iz n0izn0iz deleted the fix-post-reactions-from-feed branch November 21, 2024 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Social Feed Everything related to the Social Feed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(feed): reactions only show up on post details page
3 participants