[Groonga-commit] droonga/droonga-engine at f9114cc [master] Discard old live nodes list

Back to archive index

Kouhei Sutou kou****@clear*****
Thu May 8 17:26:24 JST 2014


> +    def self_changed?
> +      changed_nodes.keys.include?(ENV["SERF_SELF_NAME"])
> +    end

changed_nodesってHashですよね?であれば、

  changed_nodes.key?(ENV["SERF_SELF_NAME"])

でいいですよ。

http://rurema.clear-code.com/2.1.0/method/Hash/i/has_key=3f.html

keys.include?だとキーの配列を作ってから比較しますが、key?だ
と配列を作らずにチェックするので、必要のないオブジェクトが登
場しなくなり、コードがスッキリすると思います。

In <f9114cc6fd70ae7fe55083981d927961583cef75 �� jenkins.clear-code.com>
  "[Groonga-commit] droonga/droonga-engine �� f9114cc [master] Discard old live nodes list" on Thu, 08 May 2014 17:19:52 +0900,
  YUKI Hiroshi <null+groonga �� clear-code.com> wrote:

> YUKI Hiroshi	2014-05-08 17:19:52 +0900 (Thu, 08 May 2014)
> 
>   New Revision: f9114cc6fd70ae7fe55083981d927961583cef75
>   https://github.com/droonga/droonga-engine/commit/f9114cc6fd70ae7fe55083981d927961583cef75
> 
>   Message:
>     Discard old live nodes list
> 
>   Modified files:
>     lib/droonga/serf_event_handler.rb
> 
>   Modified: lib/droonga/serf_event_handler.rb (+10 -0)
> ===================================================================
> --- lib/droonga/serf_event_handler.rb    2014-05-08 17:03:22 +0900 (698d49a)
> +++ lib/droonga/serf_event_handler.rb    2014-05-08 17:19:52 +0900 (ea9ab63)
> @@ -57,7 +57,15 @@ module Droonga
>        @payload = $stdin
>      end
>  
> +    def self_changed?
> +      changed_nodes.keys.include?(ENV["SERF_SELF_NAME"])
> +    end
> +
>      def changed_nodes
> +      @changed_nodes ||= parse_changed_nodes
> +    end
> +
> +    def parse_changed_nodes
>        nodes = {}
>        @payload.each_line do |node|
>          name, address, role, tags = node.strip.split(/\s+/)
> @@ -71,6 +79,8 @@ module Droonga
>      end
>  
>      def last_live_nodes
> +      return {} if self_changed?
> +
>        return {} unless @live_nodes_file
>        return {} unless @live_nodes_file.exist?
>  




More information about the Groonga-commit mailing list
Back to archive index