Expected:number of comments should reflect Total number of comments ,when there are more than 5 comments and 'show more' button is displayed
Actual: for ex: When there are 8 comments exist for a post, only 5 comments are displayed (number of comments also shown as 5)and rest of the comments are displayed with 'show more' option. After clicking,'show more' then the total becomes 8.
Expected behaviour would be , total number of comments should be displayed even if the page shows fewer comments.
Need this fix for post->details page and My profile
From Feed , number of comments =8

From Details page

I think for this one the total number of comments should also be aggregated in the backend so that the FE can use it, thoughts? @joshmorel
@nr431207 So actually the num of comments comes from the backend. This might be a FE issue rather than a backend one. I think we just have to change some logic on the FE on when to display the num of comments and what that would be...
Yeah so it looks like there is a limit on how many comments should be showed, and the initial numOfComments has that limit which is 5...

for reference for you guys...
@idjevm yes thats right, it does come from the backend however it is being paginated, so it sends 5 comments per load, I still think the total num also needs to be aggregated in the backend, I will look into this more tho, looks like for having multiple aggregations $facet stage is used? @joshmorel
Hey guys, we're talking about the numComments field at GET /api/posts/:postId?
@Naraujo13 yes!
I worked on this before, I can take a look at the aggregation (though I think it is a condition that is wrapping it).
Anyway, this endpoint seems to return the post + first page of comments.
Is the frontend using the comments returned here or directly calling GET /api/posts:/postId/comments for all pages?
Thatd be great, Thanks @Naraujo13 !
for this casePost.js component is using this endpoint /api/posts/${postId}/comments?limit=${
limit.current * page
}&skip=${skip} with the limit of 5, so we dont have access to total numComments when it loads the page the first time.
Okay, so can I remove the comments from GET /api/posts:/postId?
This way, GET /api/posts:/postId/comments would return solely the post info (content, title, author, etc + total number of comments).
While GET /api/posts:/postId/comments would be the comments themselves.
isnt there already a route like that? that returns that information?
Currently, GET /api/posts:/postId/comments returns the whole post + first page of comments.
Currently, GET /api/posts:/postId/comments returns a page of comments.
I'm just asking if the first page of comments returned in the first endpoint is really necessary since the second can be used for that.
It's just that paging the comments to return on the first endpoint + counting them all will require facet as you noted. If it is not necessary, it is really easier and simplifies the pipeline (and has better performance), while keeping functionality.
I think as long as I can have access to the total num of comments and be able to keep the pagination, either way works for the FE 馃憤
I've updated the endpoint at #1215 (it was always returning 0 because of some recent changes) and now is returning the correct amount.
But checking the results, the frontend is still displaying the incorrect amount.
It seems to be dynamically showing the number of loaded comments instead of the static number returned by the endpoint since it seems to start with 5 and increase when you load more.
TBH I've never worked with React before so I didn't trace it back more, any help here would be appreciated.
@Naraujo13 thanks for making the changes, I will look into the FE portion and will update you if more changes need to be made :)
Comment numbers are displayed correctly.
Enhancements needed for 'Show More'/'show less' button. Refer(1243)