Rewrites lead to a working spec file.

toying-with-ramdb
Philippe PITTOLI 2024-05-09 01:32:57 +02:00
parent dd7ed3010d
commit 5bf6b21d5d
5 changed files with 22 additions and 9 deletions

View File

@ -274,23 +274,17 @@ abstract class DODB::Storage(V)
private def remove_indexing!
@indexers.each do |indexer|
FileUtils.rm_rf indexer.indexing_directory
indexer.nuke_index
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
# index directories, not the indices based on our current (and
# possiblly different from whats stored) data.
def reindex_everything!
old_data = to_h
remove_indexing!
remove_data!
old_data.each do |index, item|
self[index] = item
each_with_index() do |item, index|
write_partitions index, item
end
end

View File

@ -169,6 +169,11 @@ class DODB::CachedIndex(V) < DODB::Index(V)
end
end
def nuke_index
super
data.clear
end
def index(key, value)
super(key, value)

View File

@ -6,5 +6,9 @@ abstract class DODB::Indexer(V)
abstract def name : String
abstract def indexing_directory : String
def nuke_index
FileUtils.rm_rf indexing_directory
end
end

View File

@ -105,6 +105,11 @@ class DODB::CachedPartition(V) < DODB::Partition(V)
# This hash contains the relation between the index key and the data keys.
property data = Hash(String, Array(Int32)).new
def nuke_index
super
data.clear
end
def index(key, value)
super(key, value)
partition = key_proc.call value

View File

@ -157,6 +157,11 @@ class DODB::CachedTags(V) < DODB::Tags(V)
end
end
def nuke_index
super
data.clear
end
def get_with_indice(tag : String) : Array(Tuple(V, Int32))
r_value = Array(Tuple(V, Int32)).new