Skip to content

Commit 43c1383

Browse files
committed
fix a few obvious bugs
1 parent ef985c9 commit 43c1383

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/Storages/Cache/ObjectStorageListObjectsCache.cpp

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,22 @@ class ObjectStorageListObjectsCachePolicy : public TTLCachePolicy<Key, Mapped, H
8787

8888
for (auto it = cache.begin(); it != cache.end(); ++it)
8989
{
90+
const auto & candidate_bucket = it->first.bucket;
9091
const auto & candidate_prefix = it->first.prefix;
9192

92-
if (prefix.starts_with(candidate_prefix) && candidate_prefix.size() > best_length)
93+
if (candidate_bucket == key.bucket && prefix.starts_with(candidate_prefix))
9394
{
94-
best_match = it;
95-
best_length = candidate_prefix.size();
95+
if (IsStaleFunction()(it->fist))
96+
{
97+
BasePolicy::remove(it->first);
98+
continue;
99+
}
100+
101+
if (candidate_prefix.size() > best_length)
102+
{
103+
best_match = it;
104+
best_length = candidate_prefix.size();
105+
}
96106
}
97107
}
98108

@@ -101,12 +111,19 @@ class ObjectStorageListObjectsCachePolicy : public TTLCachePolicy<Key, Mapped, H
101111

102112
auto findAnyMatchingPrefix(const Key & key) const
103113
{
114+
const auto & bucket = key.bucket;
104115
const auto & prefix = key.prefix;
105116
return std::find_if(cache.begin(), cache.end(), [&](const auto & it)
106117
{
118+
const auto & candidate_bucket = it.first.bucket;
107119
const auto & candidate_prefix = it.first.prefix;
108-
if (prefix.starts_with(candidate_prefix))
120+
if (candidate_bucket == key.bucket && prefix.starts_with(candidate_prefix))
109121
{
122+
if (IsStaleFunction()(it->fist))
123+
{
124+
BasePolicy::remove(it->first);
125+
continue;
126+
}
110127
return true;
111128
}
112129

0 commit comments

Comments
 (0)