ruby on rails - Tire ActiveModel callback slow -
i've table shows data elasticsearch via tire. table retrieves data async in json format. if try change entry table still shows "old" state of entry (the action redirect directly after save index/table). same when delete or add entry.
but happens sometimes. found out when add "sleep(0.3)" index action before data retrieved works.
my model:
# encoding: utf-8 class group include mongoid::document include mongoid::timestamps include tire::model::search include tire::model::callbacks # relations has_and_belongs_to_many :users, index: true has_many :group_rights, dependent: :destroy accepts_nested_attributes_for :group_rights, allow_destroy: true, autosave: true ### # validates validates :name, presence: true validates :description, presence: true ### # mongoid fields field :name, type: string field :description, type: string ### # elasticsearch index_name "#{tire::model::search.index_prefix}groups" # indexname /initializers/tire.rb mapping indexes :_id, :index => :not_analyzed indexes :name indexes :description end def to_indexed_json to_json end ### # methods ### end i think have tire callback. why slow?is there maybe better way update index accordingly.
i'm using elasticsearch 0.90 openjdk-6 on debian squeeze.
thanks, patrick
elasticsearch doesn't write updates index immediately, has refresh-interval defaults 1 second, if write , read happening in under 1 second cause of problem. lower refresh-interval (i don't advise this) or call refresh after write elasticsearch in controller with
tire.index("whatever").refresh
Comments
Post a Comment