Fix delete functions for tags & partition.

toying-with-ramdb
Philippe PITTOLI 2024-05-08 21:32:21 +02:00
parent 031175a90a
commit a141849f2a
2 changed files with 30 additions and 16 deletions

View File

@ -203,11 +203,12 @@ class DODB::RAMOnlyPartition(V) < DODB::CachedPartition(V)
end
def delete(partition, &matcher)
new_partition = @data[partition].select do |key|
item = @storage[key]
! yield item
if keys = @data[partition]?
new_partition = keys.select do |key|
item = @storage[key]
! yield item
end
@data[partition] = new_partition
end
@data[partition] = new_partition
end
end

View File

@ -171,6 +171,18 @@ class DODB::CachedTags(V) < DODB::Tags(V)
r_value
end
def delete(tag, &matcher)
# Use `get_with_indexes` to retrieve data on-disk, if necessary.
new_tag = get_with_indexes(tag).map(&.[1]).select do |key|
item = @storage[key]
! yield item
end
@data[tag] = new_tag
super(tag, matcher)
end
end
# TODO
@ -191,7 +203,6 @@ class DODB::RAMOnlyTags(V) < DODB::CachedTags(V)
end
def deindex(key, value)
super(key, value)
indices = key_proc.call value
indices.each do |tag|
@ -209,18 +220,20 @@ class DODB::RAMOnlyTags(V) < DODB::CachedTags(V)
keys.each do |data_key|
r_value << { @storage[data_key], data_key }
end
else
# Get the key from the database representation on the file-system.
tag_directory = indexing_directory tag
raise MissingEntry.new(@name, tag) unless Dir.exists? tag_directory
Dir.each_child tag_directory do |child|
r_value << { @storage[get_key child], get_key child }
end
@data[tag] = r_value.map &.[1]
end
r_value
end
def delete(tag, &matcher)
# Use `get_with_indexes` to retrieve data on-disk, if necessary.
if keys = @data[tag]?
new_tag = keys.select do |key|
item = @storage[key]
! yield item
end
@data[tag] = new_tag
end
end
end