2011-08-27 3 views

답변

7

절대적으로 병행 성 문제가있을 수 있습니다.

Item.increment_counter(:total_bids, item.id) 

이 데이터베이스에 대한 SQL을 실행합니다 : 레일이 처리하는 increment_counter 제공

UPDATE items SET total_bids = total_bids + 1 WHERE id = x 

자세한 내용은 여기를 참조하십시오 : 당신이 Sidekiq를 사용하거나이있는 경우 http://api.rubyonrails.org/classes/ActiveRecord/CounterCache.html#method-i-increment_counter

+0

카운트를 10으로 설정하거나 2 씩 감소 시키려면 어떻게합니까? – Blankman

+1

그런 다음보다 일반적인 update_counters 루틴을 참조하십시오 : Item.update_counters item.id, : total_bids => -2 – asc99c

0

비슷한 작업 대기열이있는 .delay 메소드를 사용해보십시오.

Item.delay.increment_counter(:total_bids, item.id) 
관련 문제