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