1
1
#include < Storages/Cache/ObjectStorageListObjectsCache.h>
2
+ #include < boost/functional/hash.hpp>
2
3
3
4
namespace DB
4
5
{
@@ -67,16 +68,6 @@ class ObjectStorageListObjectsCachePolicy : public TTLCachePolicy<Key, Mapped, H
67
68
return std::nullopt ;
68
69
}
69
70
70
- bool contains (const Key & key) const override
71
- {
72
- if (cache.contains (key))
73
- {
74
- return true ;
75
- }
76
-
77
- return findAnyMatchingPrefix (key) != cache.end ();
78
- }
79
-
80
71
private:
81
72
auto findBestMatchingPrefix (const Key & key)
82
73
{
@@ -85,16 +76,18 @@ class ObjectStorageListObjectsCachePolicy : public TTLCachePolicy<Key, Mapped, H
85
76
auto best_match = cache.end ();
86
77
size_t best_length = 0 ;
87
78
79
+ std::vector<Key> to_remove;
80
+
88
81
for (auto it = cache.begin (); it != cache.end (); ++it)
89
82
{
90
83
const auto & candidate_bucket = it->first .bucket ;
91
84
const auto & candidate_prefix = it->first .prefix ;
92
85
93
86
if (candidate_bucket == key.bucket && prefix.starts_with (candidate_prefix))
94
87
{
95
- if (IsStaleFunction ()(it->fist ))
88
+ if (IsStaleFunction ()(it->first ))
96
89
{
97
- BasePolicy::remove (it->first );
90
+ to_remove. push_back (it->first );
98
91
continue ;
99
92
}
100
93
@@ -106,29 +99,10 @@ class ObjectStorageListObjectsCachePolicy : public TTLCachePolicy<Key, Mapped, H
106
99
}
107
100
}
108
101
109
- return best_match;
110
- }
111
-
112
- auto findAnyMatchingPrefix (const Key & key) const
113
- {
114
- const auto & bucket = key.bucket ;
115
- const auto & prefix = key.prefix ;
116
- return std::find_if (cache.begin (), cache.end (), [&](const auto & it)
117
- {
118
- const auto & candidate_bucket = it.first .bucket ;
119
- const auto & candidate_prefix = it.first .prefix ;
120
- if (candidate_bucket == key.bucket && prefix.starts_with (candidate_prefix))
121
- {
122
- if (IsStaleFunction ()(it->fist ))
123
- {
124
- BasePolicy::remove (it->first );
125
- continue ;
126
- }
127
- return true ;
128
- }
102
+ for (const auto & k : to_remove)
103
+ BasePolicy::remove (k);
129
104
130
- return false ;
131
- });
105
+ return best_match;
132
106
}
133
107
};
134
108
@@ -146,7 +120,12 @@ bool ObjectStorageListObjectsCache::Key::operator==(const Key & other) const
146
120
147
121
size_t ObjectStorageListObjectsCache::KeyHasher::operator ()(const Key & key) const
148
122
{
149
- return std::hash<String>()(key.prefix ) + std::hash<String>()(key.bucket );
123
+ std::size_t seed = 0 ;
124
+
125
+ boost::hash_combine (seed, std::hash<String>()(key.bucket ));
126
+ boost::hash_combine (seed, std::hash<String>()(key.prefix ));
127
+
128
+ return seed;
150
129
}
151
130
152
131
bool ObjectStorageListObjectsCache::IsStale::operator ()(const Key & key) const
@@ -160,7 +139,7 @@ size_t ObjectStorageListObjectsCache::WeightFunction::operator()(const Value & v
160
139
161
140
for (const auto & object : value)
162
141
{
163
- weight += object->relative_path .size () + sizeof (ObjectMetadata);
142
+ weight += object->relative_path .capacity () + sizeof (ObjectMetadata);
164
143
}
165
144
166
145
return weight;
0 commit comments