[Groonga-commit] droonga/droonga-engine at 6573fca [master] Extract codes to scan table related objects in Groonga database

Back to archive index

YUKI Hiroshi null+****@clear*****
Tue Apr 21 20:10:17 JST 2015


YUKI Hiroshi	2015-04-21 20:10:17 +0900 (Tue, 21 Apr 2015)

  New Revision: 6573fca9f81911f35f3dd7907a392f9b5a188ce3
  https://github.com/droonga/droonga-engine/commit/6573fca9f81911f35f3dd7907a392f9b5a188ce3

  Message:
    Extract codes to scan table related objects in Groonga database

  Added files:
    lib/droonga/database_scanner.rb
  Modified files:
    lib/droonga/plugins/dump.rb

  Added: lib/droonga/database_scanner.rb (+80 -0) 100644
===================================================================
--- /dev/null
+++ lib/droonga/database_scanner.rb    2015-04-21 20:10:17 +0900 (0cbcc87)
@@ -0,0 +1,80 @@
+# Copyright (C) 2015 Droonga Project
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+require "groonga"
+
+module Droonga
+  module DatabaseScanner
+    def n_all_objects
+      n_tables  = 0
+      n_columns = 0
+      n_records = 0
+      each_table do |table|
+        n_tables += 1
+        n_columns += table.columns.size
+        unless index_only_table?(table)
+          n_records += table.size
+        end
+      end
+      n_tables + n_columns + n_records
+    end
+
+    def each_table(&block)
+      options = {
+        :ignore_missing_object => true,
+        :order_by => :key,
+      }
+      reference_tables = []
+      @context.database.each(options) do |object|
+        next unless table?(object)
+        if reference_table?(object)
+          reference_tables << object
+          next
+        end
+        yield(object)
+      end
+      reference_tables.each do |reference_table|
+        yield(object)
+      end
+    end
+
+    def table?(object)
+      object.is_a?(::Groonga::Table)
+    end
+
+    def reference_table?(table)
+      table.support_key? and table?(table.domain)
+    end
+
+    def index_only_table?(table)
+      return false if table.columns.empty?
+      table.columns.all? do |column|
+        index_column?(column)
+      end
+    end
+
+    def index_column?(column)
+      column.is_a?(::Groonga::IndexColumn)
+    end
+
+    def each_index_columns(&block)
+      each_table do |table|
+        table.columns.each do |column|
+          yield(column) if index_column?(column)
+        end
+      end
+    end
+  end
+end

  Modified: lib/droonga/plugins/dump.rb (+4 -58)
===================================================================
--- lib/droonga/plugins/dump.rb    2015-04-21 19:55:10 +0900 (2c7e902)
+++ lib/droonga/plugins/dump.rb    2015-04-21 20:10:17 +0900 (1900745)
@@ -18,6 +18,7 @@ require "groonga"
 require "droonga/plugin"
 require "droonga/plugin/async_command"
 require "droonga/error_messages"
+require "droonga/database_scanner"
 
 module Droonga
   module Plugins
@@ -62,6 +63,8 @@ module Droonga
       end
 
       class Dumper < AsyncCommand::AsyncHandler
+        include DatabaseScanner
+
         def initialize(context, loop, messenger, request)
           @context = context
           super(loop, messenger, request)
@@ -116,31 +119,12 @@ module Droonga
         end
 
         def forecast
-          n_tables  = 0
-          n_columns = 0
-          n_records = 0
-          each_table do |table|
-            n_tables += 1
-            n_columns += table.columns.size
-            unless index_only_table?(table)
-              n_records += table.size
-            end
-          end
-          n_dump_messages = n_tables + n_columns + n_records
-          forward("#{prefix}.forecast", "nMessages" => n_dump_messages)
+          forward("#{prefix}.forecast", "nMessages" => n_all_objects)
         end
 
         def dump_schema
           reference_tables = []
           each_table do |table|
-            if reference_table?(table)
-              reference_tables << table
-              next
-            end
-            dump_table(table)
-          end
-
-          reference_tables.each do |table|
             dump_table(table)
           end
         end
@@ -268,44 +252,6 @@ module Droonga
           end
         end
 
-        def each_table
-          options = {
-            :ignore_missing_object => true,
-            :order_by => :key,
-          }
-          @context.database.each(options) do |object|
-            next unless table?(object)
-            yield(object)
-          end
-        end
-
-        def table?(object)
-          object.is_a?(::Groonga::Table)
-        end
-
-        def index_only_table?(table)
-          return false if table.columns.empty?
-          table.columns.all? do |column|
-            index_column?(column)
-          end
-        end
-
-        def reference_table?(table)
-          table.support_key? and table?(table.domain)
-        end
-
-        def index_column?(column)
-          column.is_a?(::Groonga::IndexColumn)
-        end
-
-        def each_index_columns
-          each_table do |table|
-            table.columns.each do |column|
-              yield(column) if index_column?(column)
-            end
-          end
-        end
-
         def setup_forward_data
           super
           @n_forwarded_messages = 0
-------------- next part --------------
HTML����������������������������...
Download 



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