Skip to content

Instantly share code, notes, and snippets.

@koshoi
Created October 29, 2020 13:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koshoi/c88e6e54bc0506894351fe1ca15de4c8 to your computer and use it in GitHub Desktop.
Save koshoi/c88e6e54bc0506894351fe1ca15de4c8 to your computer and use it in GitHub Desktop.
_G.ls = setmetatable({}, {
__serialize = function()
local res = {}
for _, sp_info in box.space._space:pairs(512, { iterator = "GE" }) do
local sp = box.space[sp_info.name]
local info = {}
info.name = tostring(sp.name)
info.engine = tostring(sp.engine)
info.len = tostring(sp:len())
info.bsize = sp:bsize()
info.owner = tostring(box.space._user:get(sp_info.owner).name)
-- index numeration starts with zero
if next(sp.index) then
for k, v in pairs(sp.index) do
if type(k) == 'number' then
info.bsize = info.bsize + v:bsize()
end
end
end
info.bsize = tostring(info.bsize):sub(1, -4) -- strip ULL
table.insert(res, info)
end
table.sort(res, function(a, b) return a.engine .. a.name < b.engine .. b.name end)
--do return res end
local nice = {}
local nice_l = {}
for _, sp in pairs(res) do
for k, v in pairs(sp) do
if not nice_l[k] then
nice_l[k] = 0
end
nice_l[k] = math.max(nice_l[k], v:len())
end
end
local split_size = tonumber(rawget(_G, '__LS_SPLIT_SIZE')) or 2
for _, sp in pairs(res) do
local str = ''
for _, k in pairs({ 'engine', 'owner', 'bsize', 'len' }) do
str = str .. ("%% -%ds%% %ds"):format(nice_l[k], split_size):format(sp[k], " ")
end
str = str .. sp['name']
table.insert(nice, str)
end
return nice
end;
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment