-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding "total" in API responses + database stats in "/status" endpoint #635
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -553,9 +553,12 @@ end | |
-- @return `res` | ||
-- @return `err` | ||
-- @return `filtering` A boolean indicating if ALLOW FILTERING was needed by the query | ||
function BaseDao:count_by_keys(where_t) | ||
function BaseDao:count_by_keys(where_t, page_size, paging_state) | ||
local select_q, where_columns, filtering = query_builder.count(self._table, where_t, self._column_family_details) | ||
local res, err = self:execute(select_q, where_columns, where_t, {}) | ||
local res, err = self:execute(select_q, where_columns, where_t, { | ||
page_size = page_size, | ||
paging_state = paging_state | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the benefit of giving the page_size and paging_state here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check where it's being used. This avoids showing a |
||
}) | ||
|
||
return (#res >= 1 and table.remove(res, 1).count or 0), err, filtering | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,6 +100,7 @@ describe("Admin API", function() | |
local body = json.decode(response) | ||
assert.truthy(body.data) | ||
assert.equal(10, table.getn(body.data)) | ||
assert.equal(10, body.total) | ||
end) | ||
|
||
it("should retrieve a paginated set", function() | ||
|
@@ -109,6 +110,7 @@ describe("Admin API", function() | |
assert.truthy(body_page_1.data) | ||
assert.equal(3, table.getn(body_page_1.data)) | ||
assert.truthy(body_page_1.next) | ||
assert.equal(10, body_page_1.total) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't add that everywhere because it makes changing the tests very painful now (for all entities). Also semantically this test (and the others) is not explaining it is testing the total count. Instead, a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The function is called If the tests themselves need to be changed, well that's another thing, in this specific case I integrated the new feature check with the existing tests. |
||
|
||
response, status = http_client.get(BASE_URL, {size=3,offset=body_page_1.next}) | ||
assert.equal(200, status) | ||
|
@@ -117,14 +119,15 @@ describe("Admin API", function() | |
assert.equal(3, table.getn(body_page_2.data)) | ||
assert.truthy(body_page_2.next) | ||
assert.not_same(body_page_1, body_page_2) | ||
assert.equal(10, body_page_2.total) | ||
|
||
response, status = http_client.get(BASE_URL, {size=4,offset=body_page_2.next}) | ||
assert.equal(200, status) | ||
local body_page_3 = json.decode(response) | ||
assert.truthy(body_page_3.data) | ||
assert.equal(4, table.getn(body_page_3.data)) | ||
-- TODO: fixme | ||
--assert.falsy(body_page_3.next) | ||
assert.equal(10, body_page_3.total) | ||
assert.falsy(body_page_3.next) | ||
assert.not_same(body_page_2, body_page_3) | ||
end) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually
count_q
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh you mean instead of
select_q
- the PR that introduced the count function has been waiting for a while under thedao/count
branch, so I merged it. Didn't spot this.