How do you handle limiting coalesce requests?

Using the JSONAPI adapter.

I have two articles. In an Ember template:

{{#each articles as |article|}}
  {{article.comments}}
{{/each}}

With coalesce enabled. If each article has a 100 comments. Ember Data will execute:

comments?filter[id]=1,2,3,4,5,6…200

The endpoint handling comments?filter[id] is expected to receive X amount of ids. The API endpoint is exposed to anyone trying to do:

comments?filter[id]=1,2,3,4,5,6…9999999

Which will be quite taxing on the database. How do you handle such situations?

Answers


If you're just trying to get all the comments for a given article, JSON API lets the server provide a "related" link with each article resource.

That is, if you request (e.g.) GET /articles/1, the server can return:

{
  "data": {
    "type": "articles",
    "id": "1",
    "attributes": { /* data for your article */ },
    "relationships": {
      "comments": {
        "links": {
          // the uri below should all the article's comments 
          // as primary data
          "related": "http://SOME_URI_HERE..." 
        }
      }
      /* other relationships would follow ... */
    }
  }
}

Then, Ember Data can (I think) be told to just follow the related link to load all the comments. However, if your server doesn't support the "related" link, or if you really do need to find a random subset of the comments by id (with filter[id]), then it's just up to the server to make sure that too many ids aren't provided. (So, if more than X ids are provided, the server is allowed to respond with an error, using the JSON API error format.)


Need Your Help

Weird font rendering in Netbeans on Linux

linux netbeans fonts

I installed NetBeans 6.8 on Linux (Mint, based on Ubuntu 9.10) and I can see that font rendering is very weird. Fonts in NetBeans are just so thin unlike any other program, be it gEdit, Eclipse, Fi...

Android SIP API - How to pickup received call

android

When using the SIP API, how can I answer a call I'm receiving. Im using the incomingcallreceiver class from sipdemo for testing and I added a pickup button in the WalkieTalkieActivity class that sh...