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

Improved performance with counter_cache for tags (tag.taggings_count) #390

Closed
wants to merge 1 commit into from

Conversation

dgilperez
Copy link

See #126 for reference.

@bf4
Copy link
Collaborator

bf4 commented Dec 10, 2013

Can you rebase against master and force push?

@dgilperez
Copy link
Author

I will not be able to do it in the following days, but if you can wait a little bit I will do it.

@bf4
Copy link
Collaborator

bf4 commented Dec 10, 2013

Great!

@bf4
Copy link
Collaborator

bf4 commented Dec 19, 2013

Rebase and remove whitespace?

@dgilperez
Copy link
Author

Done! Tests are green, though I've no time atm to manually check everything is working as expected.

@seuros
Copy link
Collaborator

seuros commented Dec 24, 2013

@dgilperez could you revert your change to db/migrate/1_acts_as_taggable_on_migration.rb and create another migration that will add the counter_cache ?

PS: how did you add a commit 2 years ago ? :)

@bf4
Copy link
Collaborator

bf4 commented Dec 24, 2013

@seuros My guess is @dgilperez cherry-picked an older commit from a previous PR when making this one... :)

@seuros
Copy link
Collaborator

seuros commented Dec 24, 2013

or he is a time traveler !

I tested this PR, everything looks fine.

@dgilperez
Copy link
Author

;)

Good guess, I cherry-picked that commit from @lichtamberg like two years ago.

I rebased again, added the migration code in a new migration file and merged the commits into a single one. Please tell me if you need anything else done.

Thanks!

TaggableModel.create(:name => "Bob", :tag_list => "ruby, rails, css")
TaggableModel.tagged_with("ruby").first.should_not be_readonly
end
else
Copy link
Collaborator

Choose a reason for hiding this comment

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

Rather than using xit to temporarily disable the test, maybe just set it as pending 'until we figure out how to test this'

Copy link
Author

Choose a reason for hiding this comment

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

Done!

@bf4
Copy link
Collaborator

bf4 commented Jan 2, 2014

Looks good to merge. Wanna update the CHANGELOG? (It's new)

@bf4
Copy link
Collaborator

bf4 commented Jan 2, 2014

Would you mind rebasing / squashing some of these commits, e.g. remove whitespace added in earlier commit?

@dgilperez
Copy link
Author

@bf4 rebased again and squashed!

About the CHANGELOG: What would you say this is for a change? A new Feature or a Misc? Also, I'm not sure how to deal with the fact that users are to be requested to run migrations again (using rake railties:install:migrations FROM=acts_as_taggable_on_engine db:migrate??) ... a warning in the bundle install log? Is this a breaking change?

Thanks !!!

@seuros
Copy link
Collaborator

seuros commented Jan 2, 2014

I think you should expand the Misc by added "Performance" to it. Place the others in the 'Unsorted'
You should also place it in the breaking change to warn for the migration requirement.

Also please look at #449 for the migration syntax.

@dgilperez
Copy link
Author

@seuros is this what you mean? 4917274

@bf4
Copy link
Collaborator

bf4 commented Jan 2, 2014

@seuros Performance is a good category. (This is a format I'm working on. Originally, I wanted to translate semver into English/devglish for the changelog. I should update notes in the rubygems style guide)

I don't consider a migration, on its own, a breaking change. Breaking change is w/r/t a change in expected behavior (e.g. returns different type) or the way to achieve it (e.g. method signature) from previous releases.

@seuros
Copy link
Collaborator

seuros commented Jan 2, 2014

@dgilperez 👍

@bf4 While some migration can be ignored ( add_index, add comment, default value), some migrations like #390 are not optional, updating the gem and not applying the migration will cause the immediate malfunction of the application .

If the database user is not a super user or has no right to alter the table. Updating the gem will cause the application to crash after the next deploy. So the notice is useful to warn for the maintenance that should be done ((Turning off/Reconfiguring) database watchers/Alter user rights, ect)

@bf4
Copy link
Collaborator

bf4 commented Jan 2, 2014

@seuros so another major version bump? ugh. Maybe we can check columns for :taggings_count and only add the counter cache if present add_counter_cache_callbacks(reflection)?

@seuros
Copy link
Collaborator

seuros commented Jan 2, 2014

@bf4 the check will be perfect, then we can remove #390 from the breaking change section.
the check can be done in-line.

@dgilperez Can you implement this check ?

@bf4
Copy link
Collaborator

bf4 commented Jan 2, 2014

@dgilperez
Copy link
Author

@bf4 @seuros I'm not quite sure on how to implement that. Maybe something in this line, from the suggested pattern? (quick & dirty).

# acts-as-taggable-on / lib / acts_as_taggable_on / acts_as_taggable_on / cache.rb
module Cache
  def self.included(base)
    base.instance_eval do
      # @private
      def _has_tags_counter_cache_columns?(db_columns)
        db_column_names = db_columns.map(&:name)
        db_column_names.include?("taggings_count")
      end

      # @private
      def _add_tags_counter_cache_methods
        add_counter_cache_callbacks(???)
      end

      def columns
        @acts_as_taggable_on_columns ||= begin
          db_columns = super
          if _has_tags_cache_columns?(db_columns)
            _add_tags_caching_methods
          end
          if _has_tags_counter_cache_columns?(db_columns)
            _add_counter_cache_callbacks
          end
          db_columns
        end
      end

Please help!

@bf4
Copy link
Collaborator

bf4 commented Jan 3, 2014

First off @acts_as_taggable_on_columns has to be a different name or will conflict with the one on cache. (feel free to change it there)

@dgilperez
Copy link
Author

Sorry guys, this is a bit ahead of my capabilities ... and worse than that, I'm leaving tomorrow for some days off and won't have much time in the next few weeks ... please feel free to step ahead, otherwise I'll come over as soon as I can. Thanks for your directions and help on this in any case !!!

@bf4
Copy link
Collaborator

bf4 commented Jan 3, 2014

Well, I put it in a local branch so someone (not necessarily me) can finish it https://github.com/mbleigh/acts-as-taggable-on/tree/dgilperez-counter_cache

@bf4
Copy link
Collaborator

bf4 commented Jan 3, 2014

I'm a sucker for this stuff sometimes. Let's see if Travis passes. Please also test yourself, both before and after running the migration, if possible. https://travis-ci.org/mbleigh/acts-as-taggable-on/builds/16298201

seuros added a commit to seuros/acts-as-taggable-on that referenced this pull request Jan 3, 2014
seuros added a commit to seuros/acts-as-taggable-on that referenced this pull request Jan 3, 2014
seuros added a commit to seuros/acts-as-taggable-on that referenced this pull request Jan 13, 2014
bf4 added a commit that referenced this pull request Jan 13, 2014
[Fix] counter_cache, Check for #390 to prevent application breakage.
@bf4
Copy link
Collaborator

bf4 commented Jan 13, 2014

Merged in manually f891175 and #390 (reference)

@bf4 bf4 closed this Jan 13, 2014
seuros added a commit to seuros/acts-as-taggable-on that referenced this pull request Feb 28, 2014
seuros added a commit to seuros/acts-as-taggable-on that referenced this pull request Feb 28, 2014
seuros added a commit that referenced this pull request Mar 14, 2014
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants