Kouhei Sutou
null+****@clear*****
Wed Feb 26 14:47:56 JST 2014
Kouhei Sutou 2014-02-26 14:47:56 +0900 (Wed, 26 Feb 2014) New Revision: be09d8c8dc641888023acc1b8f02ade2f18075c6 https://github.com/droonga/fluent-plugin-droonga/commit/be09d8c8dc641888023acc1b8f02ade2f18075c6 Message: Extract preparing data code as a method to be overriden Modified files: lib/droonga/catalog/base.rb Modified: lib/droonga/catalog/base.rb (+19 -15) =================================================================== --- lib/droonga/catalog/base.rb 2014-02-26 14:44:17 +0900 (256cf0e) +++ lib/droonga/catalog/base.rb 2014-02-26 14:47:56 +0900 (b7ecd10) @@ -32,21 +32,7 @@ module Droonga validate raise MultiplexError.new(@errors) unles****@error*****? - @data["datasets"].each do |name, dataset| - number_of_partitions = dataset["number_of_partitions"] - next if number_of_partitions < 2 - total_weight = compute_total_weight(dataset) - continuum = [] - dataset["ring"].each do |key, value| - points = number_of_partitions * 160 * value["weight"] / total_weight - points.times do |point| - hash = Digest::SHA1.hexdigest("#{key}:#{point}") - continuum << [hash[0..7].to_i(16), key] - end - end - dataset["continuum"] = continuum.sort do |a, b| a[0] - b[0]; end - end - @options = @data["options"] || {} + prepare_data end def option(name) @@ -143,6 +129,24 @@ module Droonga end private + def prepare_data + @data["datasets"].each do |name, dataset| + number_of_partitions = dataset["number_of_partitions"] + next if number_of_partitions < 2 + total_weight = compute_total_weight(dataset) + continuum = [] + dataset["ring"].each do |key, value| + points = number_of_partitions * 160 * value["weight"] / total_weight + points.times do |point| + hash = Digest::SHA1.hexdigest("#{key}:#{point}") + continuum << [hash[0..7].to_i(16), key] + end + end + dataset["continuum"] = continuum.sort do |a, b| a[0] - b[0]; end + end + @options = @data["options"] || {} + end + def compute_total_weight(dataset) dataset["ring"].reduce(0) do |result, zone| result + zone[1]["weight"] -------------- next part -------------- HTML����������������������������...Download