Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'develop' of https://github.com/CartoDB/cartodb20 into d…

…evelop
  • Loading branch information...
commit 0e9c366b82ca0b9ef1d97eda307ab92012113ae8 2 parents 315b19c + 50a4cc2
@xavijam xavijam authored
Showing with 11 additions and 21 deletions.
  1. +11 −21 app/controllers/api/json/tables_controller.rb
View
32 app/controllers/api/json/tables_controller.rb
@@ -8,35 +8,24 @@ class Api::Json::TablesController < Api::ApplicationController
after_filter :record_query_threshold
def index
- limit = params[:per_page].nil? || params[:per_page].to_i > 100 ? 100 : params[:per_page].to_i
- offset = params[:page].nil? || params[:page].to_i < 0 ? 0 : limit*(params[:page].to_i - 1)
- q = "%#{params[:q].to_s.strip}%"
- @tables = if !params[:tag_name].blank?
+ @tables = unless params[:tag_name].blank?
tag_name = params[:tag_name].sanitize.tr('_',' ')
- tables_count = Table.fetch("select count(user_tables.id) as count
- from user_tables, tags
- where user_tables.user_id = ?
- and user_tables.name like ?
- and user_tables.id = tags.table_id
- and tags.name = ?", current_user.id, q, tag_name).first[:count]
Table.fetch("select user_tables.*,
array_to_string(array(select tags.name from tags where tags.table_id = user_tables.id),',') as tags_names
from user_tables, tags
where user_tables.user_id = ?
- and user_tables.name like ?
and user_tables.id = tags.table_id
- and tags.name = ?
- order by user_tables.id DESC
- limit ? offset ?", current_user.id, q, tag_name, limit, offset).all
+ and tags.name = ? order by user_tables.id desc", current_user.id, tag_name)
else
- Table.fetch("select *, array_to_string(array(select tags.name from tags where tags.table_id = user_tables.id),',') as tags_names
- from user_tables
- where user_tables.user_id = ? and user_tables.name like ? order by id DESC
- limit ? offset ?", current_user.id, q, limit, offset).all
+ where = (params[:q].to_s.strip.blank? ? {} : :name.like("%#{params[:q]}%"))
+ current_user.tables.select("*, array_to_string(array(select tags.name from tags where tags.table_id = user_tables.id),',') as tags_names".lit)
+ .where(where).order(:id.desc)
end
- render_jsonp({ :total_entries => @tables.size,
- :tables => @tables.map { |table|
+
+ page = params[:page].to_i > 0 ? params[:page].to_i : 1
+ per_page = params[:per_page].to_i > 0 ? params[:per_page].to_i : 1000
+ render_jsonp({ :tables => @tables.paginate(page, per_page).all.map { |table|
{ :id => table.id,
:name => table.name,
:privacy => table_privacy_text(table),
@@ -46,7 +35,8 @@ def index
:rows_counted => table.rows_estimated,
:table_size => table.table_size
}
- }
+ },
+ :total_entries => @tables.count
})
end
Please sign in to comment.
Something went wrong with that request. Please try again.