lib/distribute_reads.rb in distribute_reads-0.3.2 vs lib/distribute_reads.rb in distribute_reads-0.3.3

- old
+ new

@@ -43,20 +43,20 @@ case connection.adapter_name when "PostgreSQL", "PostGIS" # cache the version number @server_version_num ||= {} cache_key = connection.pool.object_id - @server_version_num[cache_key] ||= connection.execute("SHOW server_version_num").first["server_version_num"].to_i + @server_version_num[cache_key] ||= connection.select_all("SHOW server_version_num").first["server_version_num"].to_i lag_condition = if @server_version_num[cache_key] >= 100000 "pg_last_wal_receive_lsn() = pg_last_wal_replay_lsn()" else "pg_last_xlog_receive_location() = pg_last_xlog_replay_location()" end - connection.execute( + connection.select_all( "SELECT CASE WHEN NOT pg_is_in_recovery() OR #{lag_condition} THEN 0 ELSE EXTRACT (EPOCH FROM NOW() - pg_last_xact_replay_timestamp()) END AS lag".squish ).first["lag"].to_f @@ -64,17 +64,17 @@ @aurora_mysql ||= {} cache_key = connection.pool.object_id unless @aurora_mysql.key?(cache_key) # makara doesn't send SHOW queries to replica by default - @aurora_mysql[cache_key] = connection.exec_query("SHOW VARIABLES LIKE 'aurora_version'").to_hash.any? + @aurora_mysql[cache_key] = connection.select_all("SHOW VARIABLES LIKE 'aurora_version'").any? end if @aurora_mysql[cache_key] - status = connection.exec_query("SELECT Replica_lag_in_msec FROM mysql.ro_replica_status WHERE Server_id = @@aurora_server_id").to_hash.first + status = connection.select_all("SELECT Replica_lag_in_msec FROM mysql.ro_replica_status WHERE Server_id = @@aurora_server_id").first status ? status["Replica_lag_in_msec"].to_f / 1000.0 : 0.0 else - status = connection.exec_query("SHOW SLAVE STATUS").to_hash.first + status = connection.select_all("SHOW SLAVE STATUS").first if status if status["Seconds_Behind_Master"].nil? # replication stopped # https://dev.mysql.com/doc/refman/8.0/en/show-slave-status.html nil