Skip to content

Commit 2ad2425

Browse files
committed
Use result.rows as fastest alternative
1 parent cfb7c16 commit 2ad2425

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,12 @@ def table_structure_with_collation(table_name, basic_structure)
505505
# Result will have following sample string
506506
# CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
507507
# "password_digest" varchar COLLATE "NOCASE");
508-
result = exec_query(sql, "SCHEMA").first
508+
result = query_value(sql, "SCHEMA")
509509

510510
if result
511511
# Splitting with left parentheses and discarding the first part will return all
512512
# columns separated with comma(,).
513-
columns_string = result["sql"].split("(", 2).last
513+
columns_string = result.split("(", 2).last
514514

515515
columns_string.split(",").each do |column_string|
516516
# This regex will match the column name and collation type and will save

activerecord/lib/active_record/relation.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,12 @@ def compute_cache_version(timestamp_column) # :nodoc:
367367
arel = query.arel
368368
end
369369

370-
result = connection.select_one(arel, nil)
370+
size, timestamp = connection.select_rows(arel, nil).first
371371

372-
if result
372+
if size
373373
column_type = klass.type_for_attribute(timestamp_column)
374-
timestamp = column_type.deserialize(result["timestamp"])
375-
size = result["size"]
374+
timestamp = column_type.deserialize(timestamp)
376375
else
377-
timestamp = nil
378376
size = 0
379377
end
380378
end

activerecord/lib/active_record/relation/finder_methods.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ def exists?(conditions = :none)
316316

317317
relation = construct_relation_for_exists(conditions)
318318

319-
skip_query_cache_if_necessary { connection.select_one(relation.arel, "#{name} Exists?") } ? true : false
319+
skip_query_cache_if_necessary { connection.select_rows(relation.arel, "#{name} Exists?").size == 1 }
320320
end
321321

322322
# This method is called whenever no records are found with either a single
@@ -416,8 +416,8 @@ def limited_ids_for(relation)
416416

417417
relation = relation.except(:select).select(values).distinct!
418418

419-
id_rows = skip_query_cache_if_necessary { @klass.connection.select_all(relation.arel, "SQL") }
420-
id_rows.map { |row| row[primary_key] }
419+
id_rows = skip_query_cache_if_necessary { @klass.connection.select_rows(relation.arel, "SQL") }
420+
id_rows.map(&:last)
421421
end
422422

423423
def using_limitable_reflections?(reflections)

0 commit comments

Comments
 (0)