我使用的是在Rails應用程序PostgreSQL的Slony聚-I複製多分貝的寶石。這大多完美地工作,但在某些情況下複製滯後。其中一種情況涉及ActiveRecord counter_cache。ActiveRecord的counter_cache給陳舊的計數與multi_db寶石
爲了清楚起見,假設以下兩種模式:
class Post < ActiveRecord::Base
has_many :comments
...
end
class Comment < ActiveRecord::Base
belongs_to :post, :counter_cache => true, :touch => true
...
end
創建註釋後,RJS被稱爲更新評論數有:
@comment.post.comments_count
隨着多分貝關閉(或從數據庫指向主數據庫的條目),這工作正常。所以,我嘗試了這樣的事情:
ActiveRecord::Base.connection_proxy.with_master do
[email protected]
count=post.comments_count
end
這仍然給出一個陳舊的結果。由於不設置:
config.cache_classes = false
它看起來像調用with_master
不工作。有關如何確定哪個數據庫multi-db使用的任何建議?或者,或者,如何處理這些問題?
我給一個嘗試。我懷疑問題可能是從rjs調用它。 –