mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Use result.rows
as fastest alternative
This commit is contained in:
parent
cfb7c16ac4
commit
2ad2425fd3
3 changed files with 8 additions and 10 deletions
|
@ -505,12 +505,12 @@ module ActiveRecord
|
||||||
# Result will have following sample string
|
# Result will have following sample string
|
||||||
# CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
# CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||||
# "password_digest" varchar COLLATE "NOCASE");
|
# "password_digest" varchar COLLATE "NOCASE");
|
||||||
result = exec_query(sql, "SCHEMA").first
|
result = query_value(sql, "SCHEMA")
|
||||||
|
|
||||||
if result
|
if result
|
||||||
# Splitting with left parentheses and discarding the first part will return all
|
# Splitting with left parentheses and discarding the first part will return all
|
||||||
# columns separated with comma(,).
|
# columns separated with comma(,).
|
||||||
columns_string = result["sql"].split("(", 2).last
|
columns_string = result.split("(", 2).last
|
||||||
|
|
||||||
columns_string.split(",").each do |column_string|
|
columns_string.split(",").each do |column_string|
|
||||||
# This regex will match the column name and collation type and will save
|
# This regex will match the column name and collation type and will save
|
||||||
|
|
|
@ -367,14 +367,12 @@ module ActiveRecord
|
||||||
arel = query.arel
|
arel = query.arel
|
||||||
end
|
end
|
||||||
|
|
||||||
result = connection.select_one(arel, nil)
|
size, timestamp = connection.select_rows(arel, nil).first
|
||||||
|
|
||||||
if result
|
if size
|
||||||
column_type = klass.type_for_attribute(timestamp_column)
|
column_type = klass.type_for_attribute(timestamp_column)
|
||||||
timestamp = column_type.deserialize(result["timestamp"])
|
timestamp = column_type.deserialize(timestamp)
|
||||||
size = result["size"]
|
|
||||||
else
|
else
|
||||||
timestamp = nil
|
|
||||||
size = 0
|
size = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -316,7 +316,7 @@ module ActiveRecord
|
||||||
|
|
||||||
relation = construct_relation_for_exists(conditions)
|
relation = construct_relation_for_exists(conditions)
|
||||||
|
|
||||||
skip_query_cache_if_necessary { connection.select_one(relation.arel, "#{name} Exists?") } ? true : false
|
skip_query_cache_if_necessary { connection.select_rows(relation.arel, "#{name} Exists?").size == 1 }
|
||||||
end
|
end
|
||||||
|
|
||||||
# This method is called whenever no records are found with either a single
|
# This method is called whenever no records are found with either a single
|
||||||
|
@ -416,8 +416,8 @@ module ActiveRecord
|
||||||
|
|
||||||
relation = relation.except(:select).select(values).distinct!
|
relation = relation.except(:select).select(values).distinct!
|
||||||
|
|
||||||
id_rows = skip_query_cache_if_necessary { @klass.connection.select_all(relation.arel, "SQL") }
|
id_rows = skip_query_cache_if_necessary { @klass.connection.select_rows(relation.arel, "SQL") }
|
||||||
id_rows.map { |row| row[primary_key] }
|
id_rows.map(&:last)
|
||||||
end
|
end
|
||||||
|
|
||||||
def using_limitable_reflections?(reflections)
|
def using_limitable_reflections?(reflections)
|
||||||
|
|
Loading…
Reference in a new issue