Kouhei Sutou
null+****@clear*****
Fri Oct 27 19:24:12 JST 2017
Kouhei Sutou 2017-10-27 19:24:12 +0900 (Fri, 27 Oct 2017) New Revision: afb7ccd9096d7238c4f42ccb3087993e0853167f https://github.com/ranguba/groonga-client/commit/afb7ccd9096d7238c4f42ccb3087993e0853167f Message: Share target index enumerate code Modified files: lib/groonga/client/command-line/groonga-client-index-check.rb test/command-line/test-index-check.rb Modified: lib/groonga/client/command-line/groonga-client-index-check.rb (+46 -70) =================================================================== --- lib/groonga/client/command-line/groonga-client-index-check.rb 2017-10-27 19:23:42 +0900 (fe75411) +++ lib/groonga/client/command-line/groonga-client-index-check.rb 2017-10-27 19:24:12 +0900 (c8ec95b) @@ -78,12 +78,27 @@ module Groonga private def run_internal succeeded = true - @methods.each do |method| - succeeded = false unless __send__("check_#{method}") + each_target_index_column do |index_column| + @methods.each do |method| + unless __send__("check_#{method}", index_column) + succeeded = false + end + end end succeeded end + def each_target_index_column + table_list.each do |table| + next unless check_target_table?(table.name) + column_list(table.name).each do |column| + next unless check_target_column?(column) + next unless column.index? + yield(column) + end + end + end + def check_target_table?(table_name) unless @index_names.count > 0 return true @@ -114,29 +129,10 @@ module Groonga false end - def missing_source?(column) - column["type"] == "index" and column["source"].empty? - end - - def check_source - missing_index_names = [] - table_list.each do |table| - unless check_target_table?(table["name"]) - next - end - column_list(table["name"]).each do |column| - unless check_target_column?(column) - next - end - if missing_source?(column) - missing_index_names << "#{column['domain']}.#{column['name']}" - end - end - end - missing_index_names.each do |column| - puts "index column:<#{column}> is missing source." - end - missing_index_names.empty? + def check_source(column) + return true unless column.source.empty? + $stderr.puts("Source is missing: <#{column.domain}.#{column.name}>") + false end def list_tokens(table_name) @@ -182,53 +178,33 @@ module Groonga broken_index_tokens end - def check_content - table_names = table_list.collect do |table| - if check_target_table?(table["name"]) - table["name"] - end - end.compact - target_columns = [] - table_names.each do |table_name| - column_list(table_name).collect do |column| - if check_target_column?(column) - target_columns << column - end - end + def check_content(index_column) + if index_column.source.empty? + $stderr.puts("Source is missing: <#{column.domain}.#{column.name}>") + return false end - if target_columns.empty? - abort_run("Failed to check <#{@index_names.join(',')}> because there is no such a LEXCON.INDEX.") - end - broken_indexes = [] - target_columns.each do |column| - table_name = column["domain"] - column_name = column["name"] - suffix = Time.now.strftime("%Y%m%d%H%M%S_%N") - new_column_name = "#{column_name}_#{suffix}" - if column["source"].empty? - puts("Failed to check <#{column['domain']}.#{column['name']}> because of missing source.") - next - end - type, source = column["source"].first.split(".") - flags = column["flags"].sub(/\|PERSISTENT/, '') - column_create(table_name, - new_column_name, - flags, - type, - source) - tokens = list_tokens(table_name) - puts "check #{tokens.count} tokens against <#{table_name}.#{column_name}>." - broken_index_tokens = verify_tokens(table_name, column_name, - new_column_name, tokens) - column_remove(table_name, new_column_name) - if broken_index_tokens.count > 0 - broken_indexes << "#{table_name}.#{column_name}" - end - end - broken_indexes.each do |index_column| - puts "<#{index_column}> is broken." + + table_name = index_column["domain"] + column_name = index_column["name"] + suffix = Time.now.strftime("%Y%m%d%H%M%S_%N") + new_column_name = "#{column_name}_#{suffix}" + type, source = index_column.sources.first.split(".") + flags = index_column["flags"].sub(/\|PERSISTENT/, '') + column_create(table_name, + new_column_name, + flags, + type, + source) + tokens = list_tokens(table_name) + broken_index_tokens = verify_tokens(table_name, column_name, + new_column_name, tokens) + column_remove(table_name, new_column_name) + if broken_index_tokens.empty? + true + else + $stderr.puts("Broken: #{table_name}.#{column_name}") + false end - broken_indexes.empty? end end end Modified: test/command-line/test-index-check.rb (+5 -9) =================================================================== --- test/command-line/test-index-check.rb 2017-10-27 19:23:42 +0900 (7fe3f45) +++ test/command-line/test-index-check.rb 2017-10-27 19:24:12 +0900 (865b4f7) @@ -43,11 +43,11 @@ column_create Terms memos_content \ Memos COMMANDS - expected = <<CLIENT_OUTPUT -index column:<Terms.memos_content> is missing source. -CLIENT_OUTPUT + error_output = <<-OUTPUT +Source is missing: <Terms.memos_content> + OUTPUT - assert_equal([false, expected, ""], + assert_equal([false, "", error_output], run_client_index_check("--method=source", "Terms.memos_content")) end @@ -71,11 +71,7 @@ load --table Memos ] COMMANDS - expected = <<CLIENT_OUTPUT -check 3 tokens against <Terms.memos_content>. -CLIENT_OUTPUT - - assert_equal([true, expected, ""], + assert_equal([true, "", ""], run_client_index_check("--method=content", "Terms.memos_content")) end -------------- next part -------------- HTML����������������������������... URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20171027/a9860bce/attachment-0001.htm