Improved memory food print by using pluck in large select.
This commit is contained in:
parent
008cfeea69
commit
e64ec3fa67
1 changed files with 9 additions and 7 deletions
|
@ -85,12 +85,13 @@ returns
|
||||||
list = []
|
list = []
|
||||||
overviews.each do |overview|
|
overviews.each do |overview|
|
||||||
query_condition, bind_condition, tables = Ticket.selector2sql(overview.condition, user)
|
query_condition, bind_condition, tables = Ticket.selector2sql(overview.condition, user)
|
||||||
|
direction = overview.order[:direction]
|
||||||
|
order_by = overview.order[:by]
|
||||||
|
|
||||||
# validate direction
|
# validate direction
|
||||||
raise "Invalid order direction '#{overview.order[:direction]}'" if overview.order[:direction] && overview.order[:direction] !~ /^(ASC|DESC)$/i
|
raise "Invalid order direction '#{direction}'" if direction && direction !~ /^(ASC|DESC)$/i
|
||||||
|
|
||||||
# check if order by exists
|
# check if order by exists
|
||||||
order_by = overview.order[:by]
|
|
||||||
if !ticket_attributes.key?(order_by)
|
if !ticket_attributes.key?(order_by)
|
||||||
order_by = if ticket_attributes.key?("#{order_by}_id")
|
order_by = if ticket_attributes.key?("#{order_by}_id")
|
||||||
"#{order_by}_id"
|
"#{order_by}_id"
|
||||||
|
@ -98,7 +99,7 @@ returns
|
||||||
'created_at'
|
'created_at'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
order_by = "tickets.#{order_by} #{overview.order[:direction]}"
|
order_by = "tickets.#{order_by}"
|
||||||
|
|
||||||
# check if group by exists
|
# check if group by exists
|
||||||
if overview.group_by.present?
|
if overview.group_by.present?
|
||||||
|
@ -117,13 +118,14 @@ returns
|
||||||
.where(access_condition)
|
.where(access_condition)
|
||||||
.where(query_condition, *bind_condition)
|
.where(query_condition, *bind_condition)
|
||||||
.joins(tables)
|
.joins(tables)
|
||||||
.order(order_by)
|
.order("#{order_by} #{direction}")
|
||||||
.limit(1000)
|
.limit(2000)
|
||||||
|
.pluck(:id, :updated_at, order_by)
|
||||||
|
|
||||||
tickets = ticket_result.map do |ticket|
|
tickets = ticket_result.map do |ticket|
|
||||||
{
|
{
|
||||||
id: ticket[:id],
|
id: ticket[0],
|
||||||
updated_at: ticket[:updated_at],
|
updated_at: ticket[1],
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue