Commit f8efe66627d591159cd8fec5e2134a6218c2c689
1 parent
f932e31b
Exists in
master
and in
28 other branches
ActionItem948: bypass ActiveRecord on hit
This way (I hope) the non-deterministic problem of StaleObjectError stops happening.
Showing
2 changed files
with
3 additions
and
1 deletions
Show diff stats
app/models/article.rb
... | ... | @@ -225,7 +225,8 @@ class Article < ActiveRecord::Base |
225 | 225 | end |
226 | 226 | |
227 | 227 | def hit |
228 | - self.increment!(:hits) | |
228 | + self.class.connection.execute('update articles set hits = hits + 1 where id = %d' % self.id.to_i) | |
229 | + self.hits += 1 | |
229 | 230 | end |
230 | 231 | |
231 | 232 | def can_display_hits? | ... | ... |
test/unit/article_test.rb
... | ... | @@ -610,6 +610,7 @@ class ArticleTest < Test::Unit::TestCase |
610 | 610 | should 'increment hit counter when hitted' do |
611 | 611 | a = Article.create!(:name => 'Test article', :profile => profile, :hits => 10) |
612 | 612 | a.hit |
613 | + assert_equal 11, a.hits | |
613 | 614 | a.reload |
614 | 615 | assert_equal 11, a.hits |
615 | 616 | end | ... | ... |