Permalink
Browse files

[cdweb] Database#fileList('/')の高速化。milkode.yamlから取得

  • Loading branch information...
1 parent 872218b commit 923d0a711c68a3a068106c95e83b069ca82d48ac @ongaeshi committed Mar 14, 2012
Showing with 15 additions and 1 deletion.
  1. +11 −0 lib/milkode/cdweb/lib/database.rb
  2. +4 −1 test/test_database.rb
View
11 lib/milkode/cdweb/lib/database.rb
@@ -23,12 +23,18 @@ def self.setup(db_dir)
@@db_dir = db_dir
end
+ attr_reader :yaml
+
def initialize
db_dir = @@db_dir || Dbdir.default_dir
open(db_dir)
@yaml = YamlFileWrapper.load_if(db_dir)
end
+ def yaml_reload
+ @yaml = YamlFileWrapper.load_if(@@db_dir || Dbdir.default_dir)
+ end
+
def open(db_dir)
dbfile = Dbdir.expand_groonga_path(db_dir)
@@ -96,6 +102,11 @@ def yaml_package_num
def fileList(base)
base_parts = base.split("/")
base_depth = base_parts.length
+
+ # 'depth==0'の時はMilkodeYaml#contentsからファイルリストを生成して高速化
+ if (base_depth == 0)
+ return @yaml.contents.sort_by{|v| v.name}.map{|v| [v.name, false] }
+ end
# shortpathにマッチするものだけに絞り込む
if (base == "")
View
5 test/test_database.rb
@@ -33,6 +33,9 @@ def setup_db
# データベースのセットアップ
Database.setup('.')
+
+ # yamlファイルのリロード
+ Database.instance.yaml_reload
end
def test_database
@@ -49,7 +52,7 @@ def t_open
def t_fileList
db = Database.instance
- assert_equal [['lib', false], ['test', false], ["notfound.file", true]], db.fileList('')
+ assert_equal [['lib', false], ["notfound.file", false], ['test', false]], db.fileList('')
assert db.fileList('test').include? ['test/test_database.rb', true]
assert_equal ['lib/milkode', false], db.fileList('lib')[0]
assert_equal ['lib/milkode/cdstk/cdstk.rb', true], db.fileList('lib/milkode/cdstk')[0]

0 comments on commit 923d0a7

Please sign in to comment.