begriffs / clean_pagination

API pagination the way RFC7233 intended it
MIT License
33 stars 3 forks source link

Collection is not displayed if Max per page > collection.size #7

Closed mpz closed 9 years ago

mpz commented 9 years ago

def index max_per_page = 100

paginate Bla.count, max_per_page do |limit, offset|
  render json: Bla.limit(limit).offset(offset)
end

end

IF max_per_page is more than Bla.count collection is NOT displayed on client

begriffs commented 9 years ago

Thanks for reporting this. I'll look into it over the weekend.

mpz commented 9 years ago

It also can be issue on Angular side, is not it?

begriffs commented 9 years ago

Sorry I haven't looked at this yet. As I mentioned in the other issue I have been pretty busy. Can you look at the gem code and suggest how to fix the problem?

begriffs commented 9 years ago

This bug is highly surprising since in many of the tests max_per_page is indeed much higher than the element count. Can you show me the HTTP response of your server? Perhaps your front-end display code has a bug.

Try doing

curl -I http://yourserver.com/route

which will output the payload and the HTTP headers.

mpz commented 9 years ago

With Max per page < collection.size (OK)

curl -I http://127.0.0.1:3000/stream
HTTP/1.1 206 Partial Content 
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Accept-Ranges: items
Range-Unit: items
Content-Range: 0-1/3
Link: <http://127.0.0.1:3000/stream>; rel="next"; items="2-4", <http://127.0.0.1:3000/stream>; rel="last"; items="2-4"
Content-Type: application/json; charset=utf-8
Cache-Control: no-cache
X-Request-Id: cfd305cc-e870-407c-a594-e85cd860c67c
X-Runtime: 0.028529
Server: WEBrick/1.3.1 (Ruby/2.1.1/2014-02-24)
Date: Sun, 07 Jun 2015 23:57:31 GMT
Content-Length: 0
Connection: Keep-Alive
Set-Cookie: request_method=HEAD; path=/

With Max per page > collection.size (BUG):

curl -I http://127.0.0.1:3000/stream
HTTP/1.1 200 OK 
X-Frame-Options: SAMEORIGIN
X-Xss-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Accept-Ranges: items
Range-Unit: items
Content-Range: 0-2/3
Content-Type: application/json; charset=utf-8
Etag: "ff33d4750813fad65f84d16d08092899"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: cf0fbe40-d81a-4db3-8f7b-832d70476017
X-Runtime: 0.031551
Server: WEBrick/1.3.1 (Ruby/2.1.1/2014-02-24)
Date: Mon, 08 Jun 2015 00:00:21 GMT
Content-Length: 0
Connection: Keep-Alive
Set-Cookie: request_method=HEAD; path=/

All times i get JSON data in response (via direct link) but in second time there are nothing on angular-side collection.

begriffs commented 9 years ago

Try setting Max per page > collection.size and then doing the curl without the -I option. This will display the response body and we can see if the JSON is missing.

mpz commented 9 years ago

I run:

curl http://0.0.0.0:3000/stream

I have valid JSON body.

Browser also recive valid JSON body but nothing are displayed in view.

BROWSER RESPONSE

Remote Address:0.0.0.0:3000
Request URL:http://0.0.0.0:3000/stream?
Request Method:GET
Status Code:200 OK
Response Headers
Accept-Ranges:items
Cache-Control:max-age=0, private, must-revalidate
Connection:Keep-Alive
Content-Length:6587
Content-Range:0-7/8
Content-Type:application/json; charset=utf-8
Date:Mon, 06 Jul 2015 03:47:01 GMT
Etag:"d5de0b9a082ee30ca2f66cbfd90d9c17"
Range-Unit:items
Server:WEBrick/1.3.1 (Ruby/2.1.1/2014-02-24)
X-Content-Type-Options:nosniff
X-Frame-Options:SAMEORIGIN
X-Request-Id:fbcb1bb5-d377-4965-bff8-64cad7ba96a2
X-Runtime:0.086906
X-Xss-Protection:1; mode=block
Request Headers

BROWSER REQUEST

Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4
Connection:keep-alive
Host:0.0.0.0:3000
Range:0-49
Range-Unit:items
Referer:http://0.0.0.0:3000/
begriffs commented 9 years ago

I think the problem is on the Angular side.

mpz commented 9 years ago

i post issue to https://github.com/begriffs/angular-paginate-anything/issues/76