Forum Discussion

PerBonomi's avatar
9 years ago

Correct Reply Count with API 2

Scenario:

One Topic with two replies.

First reply was, obviously, a reply to the OP.

Second reply was a reply to the first reply.

 

Using the original API(/threads/id/<id>/replies/count) I get: 2.

Using API 2 (SELECT count(*) FROM messages WHERE parent.id = '<id>') I get: 1.

 

Now, I did this test because I was getting this mismatch on an existing topic and I figured that the issue is the "parent" in the "parent.id". Because the second reply was a reply to the reply and not, technically a reply to the OP, it isn't being nested and not considered a child of the topic (I guess)?

 

Is this a bug, or is there another, better, way to count ALL replies/messages in a topic?

  • PerBonomi VarunGrazitti Using APIv2 you could query for the message count of the whole conversation:

     

    SELECT conversation.messages_count FROM messages WHERE id = '<id>' AND depth = 0

    The conversation.messages_count includes the original post. To get the count of all replies only you could simply do something like

     

    <#assign true_reply_count = (messages_count?number - 1) />

     

    Kind regards,

    Christian

     

     

     

  • PerBonomi VarunGrazitti Using APIv2 you could query for the message count of the whole conversation:

     

    SELECT conversation.messages_count FROM messages WHERE id = '<id>' AND depth = 0

    The conversation.messages_count includes the original post. To get the count of all replies only you could simply do something like

     

    <#assign true_reply_count = (messages_count?number - 1) />

     

    Kind regards,

    Christian

     

     

     

  • PerBonomi - I ran the same tests and I think this is a bug when you compare V1 with the V2. Here's how:

     

    I created a posts and replied to OP. Results for V2:

     

    SELECT count(*) FROM messages WHERE parent.id = '2578'

    Count - 1

     

    Results for V1:

     

    /restapi/vc/threads/id/2578/replies/count

    Count - 1

     

    So far, good.

     

    Now, I reply to the reply. Results for V2

    SELECT count(*) FROM messages WHERE parent.id = '2578'

    Count - 1

     

    Results for V1

    /restapi/vc/threads/id/2578/replies/count

    Count - 2

     

    The issue seems to be with the V1 call here, ideally, the call should be made as 

     

    /restapi/vc/messages/id/2578/replies/count

     

    but, this call still returns count as 2, whereas it should only return the replies of the OP, i.e. 1 in case we are making the call as /messages, because /threads means overall thread whilst the /message means we are specifying a parent post.

     

    At present, there is no difference in the results of both the following calls when made for OP

     

    /restapi/vc/threads/id/2578/replies/count

    /restapi/vc/messages/id/2578/replies/count