diff --git a/src/storage/v2/disk/storage.cpp b/src/storage/v2/disk/storage.cpp index 422a9f4d5..7c118a56d 100644 --- a/src/storage/v2/disk/storage.cpp +++ b/src/storage/v2/disk/storage.cpp @@ -550,11 +550,9 @@ VerticesIterable DiskStorage::DiskAccessor::Vertices(LabelId label, View view) { utils::SkipList *indexed_vertices{nullptr}; std::list *index_deltas{nullptr}; - auto merge_with_main_cache = [&](auto &index, auto &index_delta_storage) -> std::unordered_set { +auto merge_with_main_cache = [&](auto &index, auto &index_delta_storage) -> std::unordered_set { indexed_vertices = &index[label]; - index_delta_storage.emplace_back(); - index_deltas = &index_delta_storage.back(); - + index_deltas = &index_delta_storage.emplace_back(); return MergeVerticesFromMainCacheWithLabelIndexCache(label, view, *index_deltas, *indexed_vertices); }; @@ -566,27 +564,23 @@ VerticesIterable DiskStorage::DiskAccessor::Vertices(LabelId label, View view) { if (transaction_.command_id > cache_ci) { cache_ci = transaction_.command_id; - } else { - if (cache.contains(label)) { - if (view == View::OLD) { - // TODO - // we do not need this merge if we can make sure that - // the removing and re-adding the same label to a given - // vertex within one transaction is not permitted. - merge_with_main_cache(cache, index_delta_storage); - return VerticesIterable(AllVerticesIterable(cache[label].access(), storage_, &transaction_, view)); - } - cache[label] = utils::SkipList(); - merge_with_main_cache(cache, index_delta_storage); - return VerticesIterable(AllVerticesIterable(cache[label].access(), storage_, &transaction_, view)); - } - - cache[label] = utils::SkipList(); - index_delta_storage.emplace_back(); - index_deltas = &index_delta_storage.back(); - LoadVerticesFromDiskLabelIndex({}, label, *index_deltas, transaction_.vertices_); + merge_with_main_cache(cache, index_delta_storage); + return VerticesIterable(AllVerticesIterable(indexed_vertices->access(), storage_, &transaction_, view)); } - + if (cache.contains(label)) { + if (view == View::NEW) { + cache[label] = utils::SkipList(); + } + // TODO + // we do not need this merge if we can make sure that + // the removing and re-adding the same label to a given + // vertex within one transaction is not permitted. + merge_with_main_cache(cache, index_delta_storage); + return VerticesIterable(AllVerticesIterable(cache[label].access(), storage_, &transaction_, view)); + } + cache[label] = utils::SkipList(); + index_deltas = &index_delta_storage.emplace_back(); + LoadVerticesFromDiskLabelIndex({}, label, *index_deltas, transaction_.vertices_); merge_with_main_cache(cache, index_delta_storage); return VerticesIterable(AllVerticesIterable(indexed_vertices->access(), storage_, &transaction_, view)); } diff --git a/src/storage/v2/disk/storage.hpp b/src/storage/v2/disk/storage.hpp index 01e8605a4..2b8286ae5 100644 --- a/src/storage/v2/disk/storage.hpp +++ b/src/storage/v2/disk/storage.hpp @@ -97,11 +97,12 @@ class DiskStorage final : public Storage { template void SyncDeletedVertices(TIndex &index, TIndexCacheKey &cache_key, std::vector> &index_delta_storage, View view, TMergeFunc &merge_func) { - if (!transaction_.vertices_to_delete_.empty()) { - index[cache_key] = utils::SkipList(); - if (view == View::OLD) { - merge_func(index, index_delta_storage); - } + if (transaction_.vertices_to_delete_.empty()) { + continue; + } + index[cache_key] = utils::SkipList(); + if (view == View::OLD) { + merge_func(index, index_delta_storage); } }