Feature #6140

REST issues response with issue count limit and offset

Added by Daniel Lindenfelser over 7 years ago. Updated almost 7 years ago.

Status:ClosedStart date:2010-08-13
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:REST API
Target version:1.1.0
Resolution:

Description

Hi i currently build a Redmine Client Application for some Mobile Devices.

I have one Problem.
When i request the issues form REST API there is no way to find out how many issues are currently on the Server.
On the other responses like the html one there are variables with the issue count, limit and page number.

I write this small patch to limit the memory usage and the slowness of query multiple times for different pages to find out how many issues i really have.

This patch add the attributes issue count, limit and current page to the issues node of the REST API response for issues (issues.xml)

0001-Add-count-limit-and-page-to-REST-issues-request.patch Magnifier (1.46 KB) Daniel Lindenfelser, 2010-08-13 16:18

0002-ops-default-page-is-1-not-zero.patch Magnifier (1.02 KB) Daniel Lindenfelser, 2010-08-13 16:18


Related issues

Related to Redmine - Defect #4745: Bug in index.xml.builder (issues) Closed 2010-02-05

Associated revisions

Revision 4489
Added by Jean-Philippe Lang almost 7 years ago

Restores object count and adds offset/limit attributes to API responses for paginated collections (#6140).

History

#2 Updated by J Doe about 7 years ago

  • Assignee set to Eric Davis

isn't this a re-introduction of Defect #4745 ?

#3 Updated by Daniel Lindenfelser about 7 years ago

hmmm ok looks like i have to do this in a other way, but generally the real issue count is really useful for all REST consuming.

#4 Updated by Eric Davis almost 7 years ago

  • Assignee deleted (Eric Davis)

I am stepping down from working on Redmine. If someone else is interesting in working on this issue, feel free to reassign it to them.

Eric Davis

#5 Updated by Jean-Philippe Lang almost 7 years ago

Daniel Lindenfelser wrote:

hmmm ok looks like i have to do this in a other way, but generally the real issue count is really useful for all REST consuming.

Indeed, it's a real problem for building a REST client. Unfortunately, adding these attributes will break activeresource clients. The problem was reported to the Rails team here but it's still present in Rails 3.0.

#6 Updated by Jean-Philippe Lang almost 7 years ago

An option would be to include these attributes for "pagination aware" clients that provide a "page" parameter.

Examples:

GET /issues.xml

=> <issues type="array">
     <issue>
       ..

GET /issues.xml?page=1

=> <issues type="array" page="1" limit="25" count="562">
     <issue>
       ..

Not ideal, but it would be a shame to omit this information just because activeresource doesn't support it.

#7 Updated by Alex Last almost 7 years ago

I posted a question on related subject to forum, no responses yet:

REST API for Issues returns different results in a Browser and for CURL
http://www.redmine.org/boards/2/topics/19904

#8 Updated by Jean-Philippe Lang almost 7 years ago

  • Tracker changed from Patch to Feature
  • Subject changed from REST issues response with issue count limit and page to REST issues response with issue count limit and offset
  • Status changed from New to Closed
  • Target version set to 1.1.0

The following attributes were added by r4489 in the response: total_count, offset, limit.

Exemple:

<issues total_count="2495" type="array" limit="25" offset="0">
  <issue>
    ...
  </issue>
</issues>

The limit is set to 25 by default and can raised to 100. It does not depend on the 'Objects per page options' application setting that applies to UI only.

Note about #4745: using active_resource 2.3.5, renaming the count attribute to total_count seems to solve the problem but it's weird because I don't see anything in the Rails code that would confirm this. Anyway, a compatibility mode was added: these attributes will be omitted if nometa=1 param is present or 'X-Redmine-Nometa' header is set. This can be set this way:

class RedmineResource < ActiveResource::Base
  self.site = 'http://localhost:3000/'
  self.user = 'xxxx'
  self.password = 'xxx'

  def self.inherited(child)
    child.headers['X-Redmine-Nometa'] = '1'
  end
end

class Issue < RedmineResource
end

#9 Updated by Alex Last almost 7 years ago

Jean-Philippe, thanks.
I have a java method getIssues(), which is supposed to load all issues with the given Query ID.

do I have to perform multiple queries to the server to go through pages when I need all issues now?
it's not very convenient...

Is this done to limit memory usage in Ruby?
how do I specify amount of issues per page in my request? This page does not explain it: http://www.redmine.org/wiki/redmine/Rest_Issues

Thanks for your help.

#10 Updated by Alex Last almost 7 years ago

I see "page" parameter is ignored.
these urls have different "page" value:

  http://academ:3000/issues.xml?project_id=testproject&query_id=2&page=0&per_page=100&key=01d7692c218a74d60d25d8eb5f62874a22ef8599
  http://academ:3000/issues.xml?project_id=testproject&query_id=2&page=1&per_page=100&key=01d7692c218a74d60d25d8eb5f62874a22ef8599

- but return the same list of tasks with offset="0" attribute:
  <?xml version="1.0" encoding="UTF-8"?><issues type="array" limit="25" total_count="50" offset="0">......

#11 Updated by Alex Last almost 7 years ago

I had to read the trunk code to find out that "offset" and "limit" parameters must be used instead of "page" and "per_page".
this query works fine:

  http://academ:3000/issues.xml?project_id=testproject&query_id=2&offset=0&limit=100&key=01d7692c218a74d60d25d8eb5f62874a22ef8599

I will update the Wiki page if I have permissions.

Also available in: Atom PDF