Module: ActiverecordMysqlSqlCache::Patches::Arel::Visitors::MySQL

Extended by:
ActiveSupport::Concern
Defined in:
lib/activerecord-mysql-sql-cache/patches/arel/visitors/mysql.rb

Instance Method Summary collapse

Instance Method Details

#visit_Arel_Nodes_SelectCore_with_sql_cache(o, collector) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/activerecord-mysql-sql-cache/patches/arel/visitors/mysql.rb', line 14

def visit_Arel_Nodes_SelectCore_with_sql_cache(o, collector)
  result = visit_Arel_Nodes_SelectCore_without_sql_cache(o, collector)
  case result
  when String
    distinct = ' DISTINCT '
    select = 'SELECT '
    if result =~ /^#{select}/
      if idx = result.index(distinct)
        result.insert(idx + distinct.length, o.mysql_sql_cache.to_s)
      else
        result.insert(select.length, o.mysql_sql_cache.to_s)
      end
    end
  else # Arel 6.0+
    if idx = result.value.index('DISTINCT')
      result.value.insert(idx + 1, o.mysql_sql_cache.to_s)
    else
      result.value.insert(1, o.mysql_sql_cache.to_s)
    end
  end
  result
end