Skip to content
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

Refactoring the count function in DAO and API #636

Merged
merged 1 commit into from
Oct 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions kong/api/crud_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ function _M.paginated_set(self, dao_collection)
return app_helpers.yield_error(err)
end

local count, err = dao_collection:count_by_keys(self.params)
local total, err = dao_collection:count_by_keys(self.params)
if err then
return app_helpers.yield_error(err)
end

local next_url
if data.next_page then
-- Parse next URL, if there are no elements then don't append it
local next_total, err = dao_collection:count_by_keys(self.params, size, data.next_page)
local next_total, err = dao_collection:count_by_keys(self.params, data.next_page)
if err then
return app_helpers.yield_error(err)
end
Expand All @@ -80,7 +80,7 @@ function _M.paginated_set(self, dao_collection)
-- This check is required otherwise the response is going to be a
-- JSON Object and not a JSON array. The reason is because an empty Lua array `{}`
-- will not be translated as an empty array by cjson, but as an empty object.
local result = #data == 0 and "{\"data\":[],\"total\":0}" or {data=data, ["next"]=next_url, total=count}
local result = #data == 0 and "{\"data\":[],\"total\":0}" or {data=data, ["next"]=next_url, total=total}

return responses.send_HTTP_OK(result, type(result) ~= "table")
end
Expand Down
8 changes: 4 additions & 4 deletions kong/dao/cassandra/base_dao.lua
Original file line number Diff line number Diff line change
Expand Up @@ -550,13 +550,13 @@ end

-- Retrieve the number of rows from the given columns/value table.
-- @param `where_t` (Optional) columns/values table by which to count entities.
-- @param `paging_state` Start page from given offset. See lua-resty-cassandra's :execute() option.
-- @return `res`
-- @return `err`
-- @return `filtering` A boolean indicating if ALLOW FILTERING was needed by the query
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, {
page_size = page_size,
function BaseDao:count_by_keys(where_t, paging_state)
local count_q, where_columns, filtering = query_builder.count(self._table, where_t, self._column_family_details)
local res, err = self:execute(count_q, where_columns, where_t, {
paging_state = paging_state
})

Expand Down