-
Notifications
You must be signed in to change notification settings - Fork 23
/
bida2.lua
46 lines (40 loc) · 1.06 KB
/
bida2.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
--
-- bida2.lua
--
-- BIDA (ver. 2)
--
-- Space 0: simple birthday storage
-- Tuple: { user_id (INT), date (INT) }
-- Index 0: TREE { date, user_id }
--
local limit = 7000
function bida2_get_users_by_birthday(birthday, userid_offset)
birthday = box.unpack('i', birthday)
userid_offset = box.unpack('i', userid_offset)
--[[
We are using user id as an offset in out tarantool request.
From documentation:
localhost> lua box.select_range(4, 1, 2, '1')
---
- '1': {'1'}
- '2': {'2'}
...
That means, that select_range() function can return users with unexpected birthday => we should filter them out
--]]
local tuples = { box.select_range(0, 0, limit, birthday, userid_offset) }
local result = {}
for _, tuple in pairs(tuples) do
if box.unpack('i', tuple[1]) == birthday then
table.insert(result, tuple[0])
end
end
return unpack(result)
end
function bida2_delete_user(userid)
userid = box.unpack('i', userid)
local tuples, tuple
tuples = { box.select(0, 1, userid) }
for _, tuple in pairs(tuples) do
box.delete(0, tuple[1], tuple[0])
end
end