Improves #reindex_everything!.
parent
3f53034b5a
commit
14825f4edd
|
@ -244,6 +244,12 @@ class DODB::DataBase(K, V)
|
|||
Dir.mkdir_p data_path
|
||||
end
|
||||
|
||||
private def remove_indexing!
|
||||
@indexers.each do |indexer|
|
||||
FileUtils.rm_rf indexer.indexing_directory
|
||||
end
|
||||
end
|
||||
|
||||
# A very slow operation that removes all indices and then rewrites
|
||||
# them all.
|
||||
# FIXME: Is this really useful in its current form? We should remove the
|
||||
|
@ -252,6 +258,9 @@ class DODB::DataBase(K, V)
|
|||
def reindex_everything!
|
||||
old_data = to_h
|
||||
|
||||
remove_indexing!
|
||||
remove_data!
|
||||
|
||||
old_data.each do |index, item|
|
||||
self[index] = item
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ class DODB::Index(V) < DODB::Indexer(V)
|
|||
getter storage_root : String
|
||||
|
||||
def initialize(@storage_root, @name, @key_proc)
|
||||
Dir.mkdir_p dir_path_indices
|
||||
Dir.mkdir_p indexing_directory
|
||||
end
|
||||
|
||||
def check!(key, value, old_value)
|
||||
|
@ -66,12 +66,12 @@ class DODB::Index(V) < DODB::Indexer(V)
|
|||
nil
|
||||
end
|
||||
|
||||
private def dir_path_indices
|
||||
def indexing_directory : String
|
||||
"#{@storage_root}/indices/by_#{@name}"
|
||||
end
|
||||
|
||||
private def file_path_index(index_key : String)
|
||||
"#{dir_path_indices}/#{index_key}.json"
|
||||
"#{indexing_directory}/#{index_key}.json"
|
||||
end
|
||||
|
||||
private def get_data_symlink_index(key : String)
|
||||
|
|
|
@ -4,5 +4,7 @@ abstract class DODB::Indexer(V)
|
|||
abstract def deindex (key : String, value : V)
|
||||
abstract def check! (key : String, value : V, old_value : V?)
|
||||
abstract def name : String
|
||||
|
||||
abstract def indexing_directory : String
|
||||
end
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ class DODB::Partition(V) < DODB::Indexer(V)
|
|||
getter storage_root : String
|
||||
|
||||
def initialize(@storage_root, @name, @key_proc)
|
||||
::Dir.mkdir_p get_partition_directory
|
||||
::Dir.mkdir_p indexing_directory
|
||||
end
|
||||
|
||||
def check!(key, value, old_value)
|
||||
|
@ -40,7 +40,7 @@ class DODB::Partition(V) < DODB::Indexer(V)
|
|||
def get(partition)
|
||||
r_value = Array(V).new
|
||||
|
||||
partition_directory = get_partition_directory partition
|
||||
partition_directory = indexing_directory partition
|
||||
Dir.each_child partition_directory do |child|
|
||||
r_value << V.from_json ::File.read "#{partition_directory}/#{child}"
|
||||
end
|
||||
|
@ -48,16 +48,16 @@ class DODB::Partition(V) < DODB::Indexer(V)
|
|||
r_value
|
||||
end
|
||||
|
||||
private def get_partition_directory
|
||||
def indexing_directory : String
|
||||
"#{@storage_root}/partitions/by_#{@name}"
|
||||
end
|
||||
|
||||
private def get_partition_directory(partition)
|
||||
"#{get_partition_directory}/#{partition}"
|
||||
private def indexing_directory(partition)
|
||||
"#{indexing_directory}/#{partition}"
|
||||
end
|
||||
|
||||
private def get_partition_symlink(partition : String, key : String)
|
||||
"#{get_partition_directory partition}/#{key}.json"
|
||||
"#{indexing_directory partition}/#{key}.json"
|
||||
end
|
||||
|
||||
private def get_data_symlink(key : String)
|
||||
|
|
|
@ -7,7 +7,7 @@ class DODB::Tags(V) < DODB::Indexer(V)
|
|||
getter storage_root : String
|
||||
|
||||
def initialize(@storage_root, @name, @key_proc)
|
||||
::Dir.mkdir_p get_tag_directory
|
||||
::Dir.mkdir_p indexing_directory
|
||||
end
|
||||
|
||||
def index(key, value)
|
||||
|
@ -41,7 +41,7 @@ class DODB::Tags(V) < DODB::Indexer(V)
|
|||
def get_with_indices(key) : Array(Tuple(V, Int32))
|
||||
r_value = Array(Tuple(V, Int32)).new
|
||||
|
||||
partition_directory = "#{get_tag_directory}/#{key}"
|
||||
partition_directory = "#{indexing_directory}/#{key}"
|
||||
|
||||
return r_value unless Dir.exists? partition_directory
|
||||
|
||||
|
@ -59,12 +59,12 @@ class DODB::Tags(V) < DODB::Indexer(V)
|
|||
get_with_indices(key).map &.[0]
|
||||
end
|
||||
|
||||
private def get_tag_directory
|
||||
def indexing_directory : String
|
||||
"#{@storage_root}/by_tags/by_#{@name}"
|
||||
end
|
||||
|
||||
private def get_tagged_entry_path(key : String, index_key : String)
|
||||
"#{get_tag_directory}/#{index_key}/#{key}.json"
|
||||
"#{indexing_directory}/#{index_key}/#{key}.json"
|
||||
end
|
||||
|
||||
private def get_data_symlink(key : String)
|
||||
|
|
Loading…
Reference in New Issue