Skip to content

Commit e2854b0

Browse files
committed
CHv3: few optims
Start at Prefix if set Stop if keys doesn't match anymore prefix Turn off the pattern matching
1 parent d200211 commit e2854b0

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

oioswift/common/middleware/container_hierarchy.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class RedisDb(object):
4848
lua_script_utilities = """
4949
local get_index = function(key, start, delimiter)
5050
-- Get index of the first delimiter of the key
51-
local index = string.find(key, delimiter, start)
51+
local index = string.find(key, delimiter, start, true)
5252
if index == nil then
5353
return #key
5454
end
@@ -93,6 +93,9 @@ class RedisDb(object):
9393
9494
if marker == "" then
9595
marker = "-"
96+
if prefix ~= "" then
97+
marker = "[" .. prefix
98+
end
9699
else
97100
marker = "[" .. marker
98101
end
@@ -107,8 +110,11 @@ class RedisDb(object):
107110
for i=1, #keys do
108111
local elem = keys[i]
109112
if recursive ~= '1' then
110-
elem = get_first_level(keys[i], prefix_len + 1,
113+
elem = get_first_level(keys[i], prefix_len + 1,
111114
delimiter)
115+
-- if we found a prefix, skip remaining stuff ?
116+
-- but we should check keys array instead
117+
-- instead triggering a new zrangebylex
112118
end
113119
114120
-- there is no `continue` instruction on Lua
@@ -126,9 +132,16 @@ class RedisDb(object):
126132
end
127133
end
128134
135+
129136
if #keys <= 1 then
130137
finish = true
131138
else
139+
if prefix ~= "" then
140+
-- if key doesn't match prefix, stop looping
141+
if string.find(keys[#keys], prefix, 1, true) == nil then
142+
finish = true
143+
end
144+
end
132145
marker = "[" .. keys[#keys]
133146
end
134147
end
@@ -548,7 +561,7 @@ def header_cb(header_dict):
548561
# empty if key does not exist
549562
for entry in key_list:
550563
matches.append((mode, entry))
551-
LOG.debug("SHARD: prefix %s / matches: %s", prefix_key, matches)
564+
LOG.debug("SHARD: prefix %s / matches: %d", prefix_key, len(matches))
552565

553566
if parse_root:
554567
matches.append((CNT, ""))

0 commit comments

Comments
 (0)