From 5bf6b21d5d09500d61d77213111a1b2d5506774c Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Thu, 9 May 2024 01:32:57 +0200 Subject: [PATCH] Rewrites lead to a working spec file. --- src/dodb.cr | 12 +++--------- src/dodb/index.cr | 5 +++++ src/dodb/indexer.cr | 4 ++++ src/dodb/partition.cr | 5 +++++ src/dodb/tags.cr | 5 +++++ 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/dodb.cr b/src/dodb.cr index fd28695..aa32c34 100644 --- a/src/dodb.cr +++ b/src/dodb.cr @@ -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 what’s 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 diff --git a/src/dodb/index.cr b/src/dodb/index.cr index 2227a6e..618f712 100644 --- a/src/dodb/index.cr +++ b/src/dodb/index.cr @@ -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) diff --git a/src/dodb/indexer.cr b/src/dodb/indexer.cr index 807cfd9..089982e 100644 --- a/src/dodb/indexer.cr +++ b/src/dodb/indexer.cr @@ -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 diff --git a/src/dodb/partition.cr b/src/dodb/partition.cr index d77430d..6389d8a 100644 --- a/src/dodb/partition.cr +++ b/src/dodb/partition.cr @@ -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 diff --git a/src/dodb/tags.cr b/src/dodb/tags.cr index 117a226..3a5d153 100644 --- a/src/dodb/tags.cr +++ b/src/dodb/tags.cr @@ -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