This is a migrated thread and some comments may be shown as answers.

get count in expand expression

8 Answers 58 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Arnaud
Top achievements
Rank 1
Arnaud asked on 28 Jun 2016, 02:02 PM

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

8 Answers, 1 is accepted

Sort by
0
Arnaud
Top achievements
Rank 1
answered on 28 Jun 2016, 03:42 PM

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

0
Arnaud
Top achievements
Rank 1
answered on 28 Jun 2016, 03:59 PM

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 :)

0
Vasil
Telerik team
answered on 29 Jun 2016, 11:53 AM
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.
 
0
Arnaud
Top achievements
Rank 1
answered on 29 Jun 2016, 02:51 PM

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

0
Anton Dobrev
Telerik team
answered on 01 Jul 2016, 12:38 PM
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.
 
0
Arnaud
Top achievements
Rank 1
answered on 01 Jul 2016, 01:12 PM

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

0
Anton Dobrev
Telerik team
answered on 05 Jul 2016, 09:43 AM
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.
 
0
Arnaud
Top achievements
Rank 1
answered on 06 Jul 2016, 08:21 AM

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!

 

Tags
General Discussion
Asked by
Arnaud
Top achievements
Rank 1
Answers by
Arnaud
Top achievements
Rank 1
Vasil
Telerik team
Anton Dobrev
Telerik team
Share this question
or