Fix #6951. Use query cache/uncache, when using not only database.yml but also DATABASE_URL. #8074

Merged
merged 1 commit into from Oct 31, 2012

Conversation

Projects
None yet
4 participants
Contributor

kennyj commented Oct 30, 2012

This PR closes #6951.

If we use DATABASE_URL, ActiveRecord::Base.configurations is not populated. Thus we can't use query cache with DATABASE_URL.

See https://github.com/rails/rails/blob/master/activerecord/lib/active_record/query_cache.rb#L7

Owner

rafaelfranca commented Oct 30, 2012

@kennyj could you add a CHANGELOG entry?

@carlosantoniodasilva carlosantoniodasilva and 2 others commented on an outdated diff Oct 30, 2012

activerecord/lib/active_record/query_cache.rb
@@ -14,7 +14,7 @@ def cache(&block)
# Disable the query cache within the block if Active Record is configured.
def uncached(&block)
- if ActiveRecord::Base.configurations.blank?
+ unless ActiveRecord::Base.connected?
yield
else
connection.uncached(&block)
@carlosantoniodasilva

carlosantoniodasilva Oct 30, 2012

Owner

Perhaps we should invert the unless..else block here, wdyt?

@steveklabnik

steveklabnik Oct 31, 2012

Member

Some people really really really hate unless/else, but it doesn't bother me.

@carlosantoniodasilva

carlosantoniodasilva Oct 31, 2012

Owner

Hehe.. I don't hate, but I try to avoid :)

Contributor

kennyj commented Oct 31, 2012

Thanks guys. I don't like unless .. else too :)
I update and added a CHANGELOG entry.

@rafaelfranca rafaelfranca added a commit that referenced this pull request Oct 31, 2012

@rafaelfranca rafaelfranca Merge pull request #8074 from kennyj/fix_6951
Fix #6951. Use query cache/uncache, when using not only database.yml but also DATABASE_URL.
85039d4

@rafaelfranca rafaelfranca merged commit 85039d4 into rails:master Oct 31, 2012

@kennyj kennyj added a commit to kennyj/rails that referenced this pull request Nov 13, 2012

@kennyj kennyj Backport #8074 to 3-2-stable. Use query cache/uncache, when using not…
… only database.yml but also DATABASE_URL.
fda9075

@rafaelfranca rafaelfranca added a commit that referenced this pull request Nov 13, 2012

@rafaelfranca rafaelfranca Merge pull request #8205 from kennyj/fix_6951-32
Backport #8074 to 3-2-stable. Use query cache/uncache, when using not only database.yml but also DATABASE_URL.
5ed0381

@tsukasaoishi tsukasaoishi added a commit to tsukasaoishi/rails that referenced this pull request Jun 28, 2017

@tsukasaoishi Tsukasa OISHI + tsukasaoishi Enable query cache if set a configurations
ActiveRecord query cache is available when a connection is connected.
Therefore, query cache is unavailable when entering the ActiveRecord::Base.cache block without being connected.

```ruby
ActiveRecord::Base.cache do
  Task.find(1) # access to database.
  Task.find(1) # access to database. unavailable query cache
end
```

If we use query cache with batch script etc, we need to connect before that.
```ruby
Task.connection

ActiveRecord::Base.cache do
  Task.find(1) # access to database.
  Task.find(1) # available query cache
end
```

Before version 3.1, query cache had been enabled if a configuration was set up.
In order to solve the `DATABASE_URL` issue(#8074), ActiveRecord has checked whether a connection is connected or not.

Today, ActiveRecord.configurations respect `DATABASE_URL`.
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/core.rb#L46
e1a4878

@tsukasaoishi tsukasaoishi added a commit to tsukasaoishi/rails that referenced this pull request Jun 28, 2017

@tsukasaoishi Tsukasa OISHI + tsukasaoishi Enable query cache if set a configurations
ActiveRecord query cache is available when a connection is connected.
Therefore, query cache is unavailable when entering the ActiveRecord::Base.cache block without being connected.

```ruby
ActiveRecord::Base.cache do
  Task.find(1) # access to database.
  Task.find(1) # access to database. unavailable query cache
end
```

If we use query cache with batch script etc, we need to connect before that.
```ruby
Task.connection

ActiveRecord::Base.cache do
  Task.find(1) # access to database.
  Task.find(1) # available query cache
end
```

Before version 3.1, query cache had been enabled if a configuration was set up.
In order to solve the `DATABASE_URL` issue(#8074), ActiveRecord has checked whether a connection is connected or not.

Today, ActiveRecord.configurations respect `DATABASE_URL`.
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/core.rb#L46
a30e2e1

@tsukasaoishi tsukasaoishi added a commit to tsukasaoishi/rails that referenced this pull request Jun 28, 2017

@tsukasaoishi Tsukasa OISHI + tsukasaoishi Enable query cache if set a configurations
ActiveRecord query cache is available when a connection is connected.
Therefore, query cache is unavailable when entering the ActiveRecord::Base.cache block without being connected.

```ruby
ActiveRecord::Base.cache do
  Task.find(1) # access to database.
  Task.find(1) # access to database. unavailable query cache
end
```

If we use query cache with batch script etc, we need to connect before that.
```ruby
Task.connection

ActiveRecord::Base.cache do
  Task.find(1) # access to database.
  Task.find(1) # available query cache
end
```

Before version 3.1, query cache had been enabled if a configuration was set up.
In order to solve the `DATABASE_URL` issue(#8074), ActiveRecord has checked whether a connection is connected or not.

Today, ActiveRecord.configurations respect `DATABASE_URL`.
https://github.com/rails/rails/blob/master/activerecord/lib/active_record/core.rb#L46
1b4360d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment