-
Notifications
You must be signed in to change notification settings - Fork 23
/
pdduch.lua
61 lines (56 loc) · 1.42 KB
/
pdduch.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function add_user(user_id, stub)
local max_tuple = box.space[0].index[1]:max()
local max_id = 0
if max_tuple ~= nil then
max_id = box.unpack( 'i', max_tuple[1] )
end
local ok, err = pcall( box.insert, 0, user_id, max_id + 1 )
if not ok and string.find( err, 'Duplicate key' ) == nil then
return err
end
end
function get_first_chunk(count)
count = box.unpack('i', count)
return box.select_limit(0, 1, 0, count)
end
function get_next_chunk(last_id, last_user_id, count)
last_id = box.unpack('i', last_id)
last_user_id = box.unpack('i', last_user_id)
count = box.unpack('i', count)
return box.select_range(0, 1, count, last_id, last_user_id)
end
function remove_users(max_id)
max_id = box.unpack('i', max_id)
local stop = false
local removed = true
while ( not stop and removed ) do
local tuples = { box.select_limit(0, 1, 0, 1000) }
removed = false
for _, tuple in pairs(tuples) do
local id = box.unpack( 'i', tuple[1] )
if ( id > max_id ) then
stop = true
break
end
tuple = box.delete( 0, box.unpack('i', tuple[0]) )
removed = true
end
end
end
function get_count()
return box.space[0]:len()
end
-- delete_all
function delete_older_than()
while (true) do
local tuples = { box.select_limit(0, 1, 0, 1000) }
local removed = false
for _, tuple in pairs(tuples) do
removed = true
tuple = box.delete( 0, box.unpack('i', tuple[0]) )
end
if not removed then
break
end
end
end