Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move cache table existence check in method #433

Closed
wants to merge 1 commit into from

Conversation

joelcogen
Copy link

It used to require a database connection during assets:precompile, which prevents deployment to Heroku

It used to require a database connection during assets:precompile, which prevents deployment to Heroku
def caching_tag_list_on?(context)
column_names.include?("cached_#{context.to_s.singularize}_list")
table_exists? && column_names.include?("cached_#{context.to_s.singularize}_list")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this cause extra queries to fire?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's cached :)

# File activerecord/lib/active_record/model_schema.rb, line 202
def table_exists?
  connection.schema_cache.table_exists?(table_name)
end

@bf4
Copy link
Collaborator

bf4 commented Dec 12, 2013

Please address failing tests :)

@bf4
Copy link
Collaborator

bf4 commented Dec 12, 2013

So, current behavior is to only include/extend/eval the including class if there's a cached_x_list column. With this patch, the caching methods will always be added. Thoughts? (Hence the failing tests)

To retain the current behavior, perhaps those checks could be done in :initialize_acts_as_taggable_on_cache? or some other class method? (Just thinking aloud)

@joelcogen
Copy link
Author

You know, I'm starting to wonder if this patch is needed at all on master...

The problem I had with 2.4 was that table_exists? was called at initialization, which raised an error if you didn't have a database connection yet (which is the case on Heroku, assets are compiled without a database connection unless you enable the user-env-compile lab).

But, now that we also call connected? maybe the problem is solved, and in a admittedly better way.

I'll try it out, and close if successful.

@bf4
Copy link
Collaborator

bf4 commented Dec 12, 2013

Well, there is issue #432 which is still open

@bf4
Copy link
Collaborator

bf4 commented Dec 16, 2013

Also, specifically for Rails 4 apps on heroku, see https://devcenter.heroku.com/articles/labs-user-env-compile#enabling

bf4 added a commit to bf4/acts-as-taggable-on that referenced this pull request Dec 19, 2013
bf4 added a commit that referenced this pull request Dec 22, 2013
[#432][#403][#433][#422] Fix checking for column cache until db connects
@bf4
Copy link
Collaborator

bf4 commented Dec 27, 2013

Fixed via #438

@bf4 bf4 closed this Dec 27, 2013
tekniklr pushed a commit to tekniklr/acts-as-taggable-on that referenced this pull request Mar 19, 2021
tekniklr pushed a commit to tekniklr/acts-as-taggable-on that referenced this pull request Mar 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants