Skip to content

Commit 5222198

Browse files
committed
Implement key_def cache
1 parent d6a7304 commit 5222198

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

crud/select/iterator.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,27 @@ local merger = require('merger')
55

66
local SELECT_FUNC_NAME = '_crud.select_on_storage'
77

8-
-- TODO: implement key_def cache
8+
local key_def_cache = {}
9+
setmetatable(key_def_cache, {__mode = 'k'})
10+
911
local function get_key_def(replicasets, space_name, index_name)
1012
-- Get requested and primary index metainfo.
1113
local conn = select(2, next(replicasets)).master.conn
1214
local primary_index = conn.space[space_name].index[0]
1315
local index = conn.space[space_name].index[index_name]
1416

17+
if key_def_cache[index] ~= nil then
18+
return key_def_cache[index]
19+
end
20+
1521
-- Create a key def.
1622
local key_def = key_def_lib.new(index.parts)
1723
if not index.unique then
1824
key_def = key_def:merge(key_def_lib.new(primary_index.parts))
1925
end
2026

27+
key_def_cache[index] = key_def
28+
2129
return key_def
2230
end
2331

0 commit comments

Comments
 (0)