get count in expand expression

9 posts, 0 answers
  1. Arnaud
    Arnaud avatar
    18 posts
    Member since:
    Mar 2016

    Posted 28 Jun Link to this post

    Hello,

    In my Hybrid (javascript) app, I'm using an expand expression filter to retrieve information about comments made to a post.

    Here is the expand expression:

    "Comments": {
                  "TargetTypeName": "FitComments",
                  "ReturnAs":"CommentsText",
                  "Fields":{"Comment":1, "CreatedAt":1, "InfoId":1},
                  "Take":2,
                  "Expand":{
                    "InfoId":{
                      "TargetTypeName": "userinfo",
                      "Fields":{"Nickname":1, "Avatar":1},
                      "Expand":{
                        "Avatar":{
                          "TargetTypeName": "Files",
                          "Fields":{"Uri":1},
                        }
                      }
                    }
                  }
                },

     

    So, I'm expanding the comments data (I guess the name of the fields are self-explanatory :) and I'm taking only 2 entries (this value will change later of course). The idea to limit the number of entries is to limit the expected time before the user obtains an answer. Anyway I believe that the maximal limit is 50 from the doc.

    The problem I have is that I would like to know the actual number of comments (to inform the user), while the retrieved "CommentsText" and "Comments" fields are now arrays of length 2... I was hoping to find an entry "count" as on other queries with paging options but there does not seem to be such an info. Another idea was to use the "ReturnAs" filter expression, hoping that the "Comments" would not have been altered, but they have the exact same length (2 in my example ofc).

     

    From this example, I believe that if the number of comments is larger than 50 (limit on expand expression), I would anyway get a Comments array of length 50, also without knowing the actual number of Comments... Am I right?

     

    Any help on how I can make such a request? Should I have to design a custom cloud function for that ?

    Thanks a lof for your help

  2. Arnaud
    Arnaud avatar
    18 posts
    Member since:
    Mar 2016

    Posted 28 Jun Link to this post

    On the same topic (sorry, I can not update my previous post :(

    When I expand the Files (nested expand), the  Uri gets appended with "/Download".

    Why is that so? Can I always consider that if an Uri is present, it will be appended with "/Download"?

    Thank you

  3. Arnaud
    Arnaud avatar
    18 posts
    Member since:
    Mar 2016

    Posted 28 Jun in reply to Arnaud Link to this post

    My bad, when I select the Uri fields, it gets totally changed to a download link and not the actual link to the image...

    It still seems a strange behavior for me :)

  4. Vasil
    Admin
    Vasil avatar
    19 posts

    Posted 29 Jun Link to this post

    Hello Arnaud,

    You are correct to expect the Comments array length to be the original size, i.e. not limited to 50. It appears that this is a bug in the API server and the expand functionality. We have logged the issue and will be looking into fixing it. For the time being you should make a separate request with the non-expanded data to get the total count of the comments and then proceed with the regular request with expand.

    On the matter of the Files API - the http://api.everlive.com/v1/<your-api-key>/Files/<file-id>/Download actually uses a 301 redirect to the file.Uri so you can use the API directly without needing to fetch the file in advance as long as you have the file Id.

    I hope this addresses your questions properly. Should you have any further queries please do not hesitate to contact us.

    Regards,
    Vasil
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  5. Arnaud
    Arnaud avatar
    18 posts
    Member since:
    Mar 2016

    Posted 29 Jun in reply to Vasil Link to this post

    Thank you very much for your answer!

    Do you have any ETA for the bug fix? the question being, do I have to implement the separate request before my app launch or not :) if it's a matter of days, it will be ok for me to wait for the fix.

    Best regards,

    Arnaud

  6. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 01 Jul Link to this post

    Hello Arnaud,

    I will try to raise the priority of this issue given the use case you provided, however, we cannot confirm any time frame at the current stage. I think that it should be more applicable to your project to either use the raw data at first and expand it on demand, when the details are requested, or perform the suggestions in the previous post.

    In regard to the Files expand, in a number of scenarios it is better to expand and retrieve the Uri field of the file instead of using the :fileId/Download path. Here you can see an example of such expression.

    Let me know if this works for you.

    Regards,
    Anton Dobrev
    Telerik
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  7. Arnaud
    Arnaud avatar
    18 posts
    Member since:
    Mar 2016

    Posted 01 Jul in reply to Anton Dobrev Link to this post

    Hello,

    Thanks again for your replies!

    Regarding the expand expression, I will follow your advice and test both approaches. I guess that, to have a smoother experience for my user, I prefer to have some initial comments loaded when the page is opened (hence, coding 2 queries as vasil suggested).

    Can I kindly ask you to update this post when a fix has been deployed? I'll keep track of your posts.

    For the Files expand, I indeed observed that using the Uri was better than the download link. I'll follow the example you provided.

    Thank you.

    Best regards,

    Arnaud

  8. Anton Dobrev
    Admin
    Anton Dobrev avatar
    539 posts

    Posted 05 Jul Link to this post

    Hello Arnaud,

    Please give a try to the suggestions and let me know if you have further questions or considerations.

    I added a remark in out issue tracking system to update this thread with the progress on the task.

    Regards,
    Anton Dobrev
    Telerik by Progress
     
    Everlive is now Telerik Backend Services, and is part of the Telerik Platform.
     
  9. Arnaud
    Arnaud avatar
    18 posts
    Member since:
    Mar 2016

    Posted 06 Jul in reply to Anton Dobrev Link to this post

    Dear,

    As suggested, I implemented your suggestions. Everything is working fine (Double backend request for the comments expansion and SingleField key for the file Uri expand), although the double request tends to be a little bit slower (as expected)...

    Thank you for your help!

     

Back to Top